-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Issue-1826] Fix bug for Transaction actions
- Loading branch information
dominhquang
committed
Nov 19, 2024
1 parent
bc6fdfc
commit 0a1821c
Showing
24 changed files
with
563 additions
and
359 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
This file was deleted.
Oops, something went wrong.
53 changes: 53 additions & 0 deletions
53
src/hooks/earning/useGetYieldPositionForSpecificAccount.ts
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright 2019-2022 @polkadot/extension-koni-ui authors & contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { YieldPositionInfo } from '@subwallet/extension-base/types'; | ||
import BigN from 'bignumber.js'; | ||
import { useMemo } from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import { RootState } from 'stores/index'; | ||
import { useGetChainSlugsByAccount } from 'hooks/useGetChainSlugsByAccount'; | ||
import { isSameAddress } from 'utils/account/account'; | ||
|
||
const useGetYieldPositionForSpecificAccount = (address?: string): YieldPositionInfo[] => { | ||
const poolInfoMap = useSelector((state: RootState) => state.earning.poolInfoMap); | ||
const yieldPositions = useSelector((state: RootState) => state.earning.yieldPositions); | ||
const isAllAccount = useSelector((state: RootState) => state.accountState.isAllAccount); | ||
const currentAccountProxy = useSelector((state: RootState) => state.accountState.currentAccountProxy); | ||
const chainsByAccountType = useGetChainSlugsByAccount(); | ||
|
||
return useMemo(() => { | ||
const infoSpecificList: YieldPositionInfo[] = []; | ||
|
||
const checkAddress = (item: YieldPositionInfo) => { | ||
if (isAllAccount) { | ||
if (address) { | ||
return isSameAddress(address, item.address); | ||
} | ||
|
||
return true; | ||
} else { | ||
return currentAccountProxy?.accounts.some(({ address: _address }) => { | ||
const compareAddress = address ? isSameAddress(address, _address) : true; | ||
|
||
return compareAddress && isSameAddress(_address, item.address); | ||
}); | ||
} | ||
}; | ||
|
||
for (const info of yieldPositions) { | ||
if (chainsByAccountType.includes(info.chain) && poolInfoMap[info.slug]) { | ||
const isValid = checkAddress(info); | ||
const haveStake = new BigN(info.totalStake).gt(0); | ||
|
||
if (isValid && haveStake) { | ||
infoSpecificList.push(info); | ||
} | ||
} | ||
} | ||
|
||
return infoSpecificList; | ||
}, [address, chainsByAccountType, currentAccountProxy?.accounts, isAllAccount, poolInfoMap, yieldPositions]); | ||
}; | ||
|
||
export default useGetYieldPositionForSpecificAccount; |
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
Oops, something went wrong.