-
Notifications
You must be signed in to change notification settings - Fork 11.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move useGetAllBalance and useGetCoinBalance to core (#12164)
## Description - Move the useGetAllBalance and useGetCoinBalance to core - Fix the reordering issue on the Token
- Loading branch information
1 parent
d1810e8
commit 12c4b3a
Showing
15 changed files
with
124 additions
and
71 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { useRpcClient } from '../api/RpcClientContext'; | ||
import { type SuiAddress, CoinBalance } from '@mysten/sui.js'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
|
||
export function useGetAllBalances<TResult = CoinBalance[]>( | ||
address?: SuiAddress | null, | ||
refetchInterval?: number, | ||
staleTime?: number, | ||
select?: (data: CoinBalance[]) => TResult | ||
) { | ||
const rpc = useRpcClient(); | ||
return useQuery({ | ||
queryKey: ['get-all-balance', address], | ||
queryFn: () => rpc.getAllBalances({ owner: address! }), | ||
enabled: !!address, | ||
refetchInterval, | ||
staleTime, | ||
select, | ||
}); | ||
} |
15 changes: 5 additions & 10 deletions
15
...let/src/ui/app/hooks/useGetCoinBalance.ts → apps/core/src/hooks/useGetCoinBalance.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 |
---|---|---|
@@ -1,28 +1,23 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { useFeatureValue } from '@growthbook/growthbook-react'; | ||
import { useRpcClient } from '@mysten/core'; | ||
import { useRpcClient } from '../api/RpcClientContext'; | ||
import { type SuiAddress } from '@mysten/sui.js'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
|
||
import { FEATURES } from '_src/shared/experimentation/features'; | ||
|
||
export function useGetCoinBalance( | ||
coinType: string, | ||
address?: SuiAddress | null | ||
address?: SuiAddress | null, | ||
refetchInterval?: number, | ||
staleTime?: number | ||
) { | ||
const rpc = useRpcClient(); | ||
const refetchInterval = useFeatureValue( | ||
FEATURES.WALLET_BALANCE_REFETCH_INTERVAL, | ||
20_000 | ||
); | ||
|
||
return useQuery({ | ||
queryKey: ['coin-balance', address, coinType], | ||
queryFn: () => rpc.getBalance({ owner: address!, coinType }), | ||
enabled: !!address && !!coinType, | ||
refetchInterval, | ||
staleTime: 5_000, | ||
staleTime, | ||
}); | ||
} |
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.
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { Coin, type CoinBalance } from '@mysten/sui.js'; | ||
|
||
// Sort tokens by symbol and total balance | ||
// Move this to the API backend | ||
export function sortGetAllBalancesToken(tokens: CoinBalance[]) { | ||
return [...tokens].sort((a, b) => | ||
(Coin.getCoinSymbol(a.coinType) + Number(a.totalBalance)).localeCompare( | ||
Coin.getCoinSymbol(b.coinType) + Number(b.totalBalance) | ||
) | ||
); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { useFeatureValue } from '@growthbook/growthbook-react'; | ||
|
||
import { FEATURES } from '_src/shared/experimentation/features'; | ||
|
||
export function useCoinsReFetchingConfig() { | ||
const refetchInterval = useFeatureValue( | ||
FEATURES.WALLET_BALANCE_REFETCH_INTERVAL, | ||
20_000 | ||
); | ||
return { | ||
refetchInterval, | ||
staleTime: 5_000, | ||
}; | ||
} |
This file was deleted.
Oops, something went wrong.
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
12c4b3a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
offline-signer-helper – ./dapps/offline-signer-helper
offline-signer-helper-git-main-mysten-labs.vercel.app
offline-signer-helper.vercel.app
offline-signer-helper-mysten-labs.vercel.app
12c4b3a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
explorer-storybook – ./apps/explorer
explorer-storybook-mysten-labs.vercel.app
explorer-storybook-git-main-mysten-labs.vercel.app
explorer-storybook.vercel.app
12c4b3a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
explorer – ./apps/explorer
explorer-mysten-labs.vercel.app
explorer.sui.io
explorer-git-main-mysten-labs.vercel.app
www.suiexplorer.com
suiexplorer.com
www.explorer.sui.io
explorer-topaz.vercel.app