-
Notifications
You must be signed in to change notification settings - Fork 11.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[wallet]: add balance in USD for recognized coins (#15399)
## Description - Add balance in USD for recognized coins - https://mysten.atlassian.net/browse/APPS-2026 - Slack thread https://mysten-labs.slack.com/archives/C042YF60NH2/p1702521120146499 <img width="386" alt="Screenshot 2023-12-15 at 10 39 30 PM" src="https://github.com/MystenLabs/sui/assets/127577476/648e1bc7-52c7-4905-986a-0167c29cc7a6"> ## Test Plan How did you test the new or updated feature? --- If your changes are not user-facing and not a breaking change, you can skip the following section. Otherwise, please indicate what changed, and then add to the Release Notes section as highlighted during the release process. ### Type of Change (Check all that apply) - [ ] protocol change - [ ] user-visible impact - [ ] breaking change for a client SDKs - [ ] breaking change for FNs (FN binary must upgrade) - [ ] breaking change for validators or node operators (must upgrade binaries) - [ ] breaking change for on-chain data layout - [ ] necessitate either a data wipe or data migration ### Release notes --------- Co-authored-by: Jordan Gensler <jordan@mystenlabs.com>
- Loading branch information
1 parent
e21ed08
commit cfcd572
Showing
3 changed files
with
52 additions
and
2 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,32 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { useQuery } from '@tanstack/react-query'; | ||
import BigNumber from 'bignumber.js'; | ||
|
||
import { useAppsBackend } from './useAppsBackend'; | ||
import { useCoinMetadata } from './useFormatCoin'; | ||
|
||
type TokenPriceResponse = { price: string | null }; | ||
|
||
export function useTokenPrice(coinType: string) { | ||
const { request } = useAppsBackend(); | ||
return useQuery({ | ||
queryKey: ['apps-backend', 'token-price', coinType], | ||
queryFn: () => request<TokenPriceResponse>(`cetus/${coinType}`), | ||
|
||
// These values are set to one minute to prevent displaying stale data, as token prices can change frequently. | ||
staleTime: 60 * 1000, | ||
gcTime: 60 * 1000, | ||
}); | ||
} | ||
|
||
export function useBalanceInUSD(coinType: string, balance: bigint | string | number) { | ||
const { data: coinMetadata } = useCoinMetadata(coinType); | ||
const { data: tokenPrice } = useTokenPrice(coinType); | ||
if (!tokenPrice || !coinMetadata || !tokenPrice.price) return null; | ||
return new BigNumber(balance.toString()) | ||
.shiftedBy(-1 * coinMetadata.decimals) | ||
.multipliedBy(tokenPrice.price) | ||
.toNumber(); | ||
} |
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
cfcd572
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:
sui-core – ./docs/site
sui-core.vercel.app
sui-core-git-main-sui-foundation.vercel.app
sui-core-sui-foundation.vercel.app
docs.sui.io
www.docs.sui.io
cfcd572
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:
sui-typescript-docs – ./sdk/docs
sui-typescript-docs-git-main-mysten-labs.vercel.app
sdks.mystenlabs.com
sdk.mystenlabs.com
sui-typescript-docs-mysten-labs.vercel.app
sui-wallet-kit.vercel.app
sui-typescript-docs.vercel.app
cfcd572
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:
mysten-ui – ./apps/ui
mysten-ui-mysten-labs.vercel.app
mysten-ui.vercel.app
mysten-ui-git-main-mysten-labs.vercel.app
cfcd572
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-topaz.vercel.app
explorer-mysten-labs.vercel.app
explorer.sui.io
www.suiexplorer.com
www.explorer.sui.io
explorer-git-main-mysten-labs.vercel.app
suiexplorer.com