-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/optional-index-canister
- Loading branch information
Showing
8 changed files
with
164 additions
and
10 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 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,10 +1,38 @@ | ||
import { type BalancesData } from '$lib/stores/balances.store'; | ||
import type { CertifiedStoreData } from '$lib/stores/certified.store'; | ||
import type { TokenId } from '$lib/types/token'; | ||
import type { Option } from '$lib/types/utils'; | ||
import { nonNullish } from '@dfinity/utils'; | ||
|
||
export const checkAnyNonZeroBalance = ($balancesStore: CertifiedStoreData<BalancesData>): boolean => | ||
nonNullish($balancesStore) && | ||
Object.getOwnPropertySymbols($balancesStore).some( | ||
(tokenId) => !($balancesStore[tokenId as TokenId]?.data?.isZero() ?? true) | ||
); | ||
|
||
/** | ||
* Check if all balances are zero. | ||
* | ||
* It requires a minimum length of the balance data to be considered valid. | ||
* This is to avoid false positives when, for example, the list of tokens is still loading, | ||
* and the number of tokens in the balance store is not the same as the number of tokens in the UI. | ||
* | ||
* @param $balancesStore - Certified store of balances. | ||
* @param minLength - Minimum length of the store to be considered valid. | ||
* @returns `true` if all balances are zero and the conditions are met, `false` otherwise. | ||
*/ | ||
|
||
export const checkAllBalancesZero = ({ | ||
$balancesStore, | ||
minLength | ||
}: { | ||
$balancesStore: CertifiedStoreData<BalancesData>; | ||
minLength: number; | ||
}): boolean => | ||
nonNullish($balancesStore) && | ||
Object.getOwnPropertySymbols($balancesStore).length >= Math.max(minLength, 1) && | ||
Object.getOwnPropertySymbols($balancesStore).every((tokenId) => { | ||
const balance: Option<BalancesData> = $balancesStore[tokenId as TokenId]; | ||
|
||
return balance === null || (balance?.data?.isZero() ?? false) || balance?.data === null; | ||
}); |
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