forked from 5afe/safe-react
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #310 from aura-nw/euphoria
Euphoria
- Loading branch information
Showing
23 changed files
with
895 additions
and
565 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
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,33 +1,45 @@ | ||
import { Action, createAction } from 'redux-actions' | ||
import { ThunkDispatch } from 'redux-thunk' | ||
import { getInternalChainId } from 'src/config' | ||
import { extractSafeAddress } from 'src/routes/routes' | ||
import { getAllDelegateOfUser } from 'src/services' | ||
import { getChainInfo } from 'src/config' | ||
import { AppReduxState } from 'src/logic/safe/store' | ||
import { extractSafeAddress } from 'src/routes/routes' | ||
import { getAllDelegations, getAllReward } from 'src/services' | ||
import { DelegationType } from '../reducer' | ||
|
||
export const FETCH_ALL_DELEGATIONS = 'FETCH_ALL_DELEGATIONS' | ||
|
||
export const fetchAllDelegations = | ||
() => | ||
async (dispatch: ThunkDispatch<AppReduxState, undefined, Action<DelegationType[]>>): Promise<void> => { | ||
try { | ||
const safeAddress = extractSafeAddress() | ||
const internalChainId = getInternalChainId() | ||
const allDelegation = (await getAllDelegateOfUser(internalChainId, safeAddress)) as any | ||
if (allDelegation.Data.delegations) { | ||
const formatedData: DelegationType[] = allDelegation.Data.delegations.map( | ||
async (dispatch: ThunkDispatch<AppReduxState, undefined, Action<DelegationType[]>>): Promise<void> => { | ||
try { | ||
const safeAddress = extractSafeAddress() | ||
const currentChainInfo = getChainInfo() as any | ||
const allDelegation = await getAllDelegations(currentChainInfo.lcd, safeAddress) | ||
const allReward = await getAllReward(currentChainInfo.lcd, safeAddress) | ||
|
||
const formatDataDelegations = allDelegation?.delegation_responses | ||
?.map((delegation: any) => { | ||
const reward = allReward?.rewards?.find( | ||
(rw: any) => rw.validator_address === delegation.delegation.validator_address, | ||
) as any | ||
return { | ||
balance: delegation.balance, | ||
operatorAddress: delegation.delegation.validator_address, | ||
reward: reward?.reward ?? [], | ||
} | ||
}) ?? [] | ||
|
||
const formatedData: DelegationType[] = formatDataDelegations.map( | ||
(delegation: any): DelegationType => ({ | ||
operatorAddress: delegation.operatorAddress, | ||
reward: delegation.reward[0]?.amount, | ||
staked: delegation.balance?.amount, | ||
}), | ||
) | ||
dispatch(setAllDelegation(formatedData)) | ||
} catch (err) { | ||
console.error('fetch delegation error', err) | ||
} | ||
} catch (err) { | ||
console.error('fetch delegation error', err) | ||
return Promise.resolve() | ||
} | ||
return Promise.resolve() | ||
} | ||
const setAllDelegation = createAction<DelegationType[]>(FETCH_ALL_DELEGATIONS) |
Oops, something went wrong.