-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add passage airdrop breakdown page
- Loading branch information
Showing
3 changed files
with
278 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.