Skip to content

Commit

Permalink
feat: add passage airdrop breakdown page
Browse files Browse the repository at this point in the history
  • Loading branch information
aleem1314 committed Oct 26, 2023
1 parent d86e290 commit 073a169
Show file tree
Hide file tree
Showing 3 changed files with 278 additions and 113 deletions.
6 changes: 6 additions & 0 deletions frontend/src/features/airdrop/airdropService.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ const getClaimRecords = (baseURL, address) => {
return Axios.get(uri)
}

const getAirdropDetails = (address) => {
const uri = `https://api.resolute.vitwit.com/passage-airdrop-details/airdrop-check?address=${address}`
return Axios.get(uri)
}

const getClaimParams = (baseURL) => {
const uri = `${cleanURL(baseURL)}${claimParamsURL}`
return Axios.get(uri)
Expand All @@ -17,6 +22,7 @@ const getClaimParams = (baseURL) => {
const result = {
claimRecords: getClaimRecords,
params: getClaimParams,
airdropDetails: getAirdropDetails,
}

export default result;
246 changes: 141 additions & 105 deletions frontend/src/features/airdrop/airdropSlice.js
Original file line number Diff line number Diff line change
@@ -1,128 +1,164 @@
import airdropService from './airdropService';
import { createAsyncThunk, createSlice } from '@reduxjs/toolkit';
import { fee, signAndBroadcastClaimMsg } from '../../txns/execute';
import { AirdropClaim } from '../../txns/passage';
import { setError, setTxHash } from '../common/commonSlice';
import airdropService from "./airdropService";
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
import { fee, signAndBroadcastClaimMsg } from "../../txns/execute";
import { AirdropClaim } from "../../txns/passage";
import { setError, setTxHash } from "../common/commonSlice";

const initialState = {
claimRecords: {},
status: '',
claimStatus: '',
errMsg: '',
params: {},
tx: {
status: 'idle'
}
}
claimRecords: {},
status: "",
claimStatus: "",
errMsg: "",
params: {},
tx: {
status: "idle",
},
airdropDetails: {},
airdropDetailsStatus: "",
};

export const getAirdropDetails = createAsyncThunk(
"airdrop/airdrop-details",
async (data) => {
const response = await airdropService.airdropDetails(data.address);
return response.data;
}
);

export const getClaimRecords = createAsyncThunk(
'airdrop/claim-records',
async (data) => {
const response = await airdropService.claimRecords(data.baseURL, data.address);
return response.data;
}
"airdrop/claim-records",
async (data) => {
const response = await airdropService.claimRecords(
data.baseURL,
data.address
);
return response.data;
}
);

export const getClaimParams = createAsyncThunk(
'airdrop/claim-params',
async (data) => {
const response = await airdropService.params(data.baseURL);
return response.data;
}
"airdrop/claim-params",
async (data) => {
const response = await airdropService.params(data.baseURL);
return response.data;
}
);

export const txClaimAction = createAsyncThunk(
'airdrop/claim-tx-1',
async (data, { rejectWithValue, fulfillWithValue, dispatch }) => {
try {
const msg = AirdropClaim(data.address)
const result = await signAndBroadcastClaimMsg(data.address, [msg], fee(data.denom, data.feeAmount, 200000),data.chainId, data.rpc, data.memo)
if (result?.code === 0) {
dispatch(setTxHash({
hash: result?.transactionHash
}))
return fulfillWithValue({ txHash: result?.transactionHash });
} else {
dispatch(setError({
type: 'error',
message: result?.rawLog
}))
return rejectWithValue(result?.rawLog);
}
} catch (error) {
dispatch(setError({
type: 'error',
message: error.message
}))
return rejectWithValue(error.message)
}
"airdrop/claim-tx-1",
async (data, { rejectWithValue, fulfillWithValue, dispatch }) => {
try {
const msg = AirdropClaim(data.address);
const result = await signAndBroadcastClaimMsg(
data.address,
[msg],
fee(data.denom, data.feeAmount, 200000),
data.chainId,
data.rpc,
data.memo
);
if (result?.code === 0) {
dispatch(
setTxHash({
hash: result?.transactionHash,
})
);
return fulfillWithValue({ txHash: result?.transactionHash });
} else {
dispatch(
setError({
type: "error",
message: result?.rawLog,
})
);
return rejectWithValue(result?.rawLog);
}
} catch (error) {
dispatch(
setError({
type: "error",
message: error.message,
})
);
return rejectWithValue(error.message);
}
)
}
);

export const airdropSlice = createSlice({
name: 'airdrop',
initialState,
reducers: {
resetState: (state) => {
state.status = ''
state.errMsg = ''
state.claimRecords = {}
state.params = {}
state.claimStatus = ''
},
resetClaimRecords: (state) => {
state.claimRecords = {}
}
name: "airdrop",
initialState,
reducers: {
resetState: (state) => {
state.status = "";
state.errMsg = "";
state.claimRecords = {};
state.params = {};
state.claimStatus = "";
},
resetClaimRecords: (state) => {
state.claimRecords = {};
},
},

extraReducers: (builder) => {
builder
.addCase(getClaimRecords.pending, (state) => {
state.claimStatus = 'pending';
state.errMsg = ''

})
.addCase(getClaimRecords.fulfilled, (state, action) => {
state.claimStatus = 'idle';
state.claimRecords = action.payload.claim_record
state.errMsg = ''
})
.addCase(getClaimRecords.rejected, (state, action) => {
state.claimStatus = 'rejected';
state.claimRecords = {}
state.errMsg = action.error.message
})

.addCase(getClaimParams.pending, (state) => {
state.status = 'pending';
state.errMsg = ''
extraReducers: (builder) => {
builder
.addCase(getClaimRecords.pending, (state) => {
state.claimStatus = "pending";
state.errMsg = "";
})
.addCase(getClaimRecords.fulfilled, (state, action) => {
state.claimStatus = "idle";
state.claimRecords = action.payload.claim_record;
state.errMsg = "";
})
.addCase(getClaimRecords.rejected, (state, action) => {
state.claimStatus = "rejected";
state.claimRecords = {};
state.errMsg = action.error.message;
})

})
.addCase(getClaimParams.fulfilled, (state, action) => {
state.status = 'idle';
state.params = action.payload.params
state.errMsg = ''
})
.addCase(getClaimParams.rejected, (state, action) => {
state.status = 'rejected';
state.params = {}
state.errMsg = action.error.message
})
.addCase(getClaimParams.pending, (state) => {
state.status = "pending";
state.errMsg = "";
})
.addCase(getClaimParams.fulfilled, (state, action) => {
state.status = "idle";
state.params = action.payload.params;
state.errMsg = "";
})
.addCase(getClaimParams.rejected, (state, action) => {
state.status = "rejected";
state.params = {};
state.errMsg = action.error.message;
})

.addCase(txClaimAction.pending, (state) => {
state.tx.status = `pending`
.addCase(txClaimAction.pending, (state) => {
state.tx.status = `pending`;
})
.addCase(txClaimAction.fulfilled, (state, _) => {
state.tx.status = `idle`;
})
.addCase(txClaimAction.rejected, (state, _) => {
state.tx.status = `rejected`;
})

})
.addCase(txClaimAction.fulfilled, (state, _) => {
state.tx.status = `idle`
})
.addCase(txClaimAction.rejected, (state, _) => {
state.tx.status = `rejected`
})
}
.addCase(getAirdropDetails.pending, (state) => {
state.airdropDetails = {};
state.airdropDetailsStatus = "pending";
})

})
.addCase(getAirdropDetails.rejected, (state, _) => {
state.airdropDetails = {};
state.airdropDetailsStatus = "rejected";
})

.addCase(getAirdropDetails.fulfilled, (state, action) => {
state.airdropDetails = action.payload;
state.airdropDetailsStatus = "fulfilled";
});
},
});

export const { resetState, resetClaimRecords } = airdropSlice.actions;
export default airdropSlice.reducer;
Loading

0 comments on commit 073a169

Please sign in to comment.