-
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.
Add total staked on address page/ fix wrong digest link format (#14368)
## Description This PR adds `STAKING` Amount on the explorer page. I moved `useGetDelegatedStake` to core and added the option to `autoRefetch` with existing predefined stale time and refresh. Fix wrong digest link format <img width="408" alt="Screenshot 2023-10-22 at 4 42 34 PM" src="https://github.com/MystenLabs/sui/assets/126525197/2f65cb14-e57f-4637-86a4-c3800f93c894"> <img width="1341" alt="Screenshot 2023-10-22 at 4 36 56 PM" src="https://github.com/MystenLabs/sui/assets/126525197/db4a3aed-c5e5-4e11-b454-d7ac186d4d94">
- Loading branch information
1 parent
0fbacf4
commit 4265d4b
Showing
18 changed files
with
166 additions
and
44 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,21 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { useSuiClient } from '@mysten/dapp-kit'; | ||
import type { DelegatedStake } from '@mysten/sui.js/client'; | ||
import { useQuery, type UseQueryOptions } from '@tanstack/react-query'; | ||
|
||
type UseGetDelegatedStakesOptions = { | ||
address: string; | ||
} & UseQueryOptions<DelegatedStake[], Error>; | ||
|
||
export function useGetDelegatedStake(options: UseGetDelegatedStakesOptions) { | ||
const client = useSuiClient(); | ||
const { address, ...queryOptions } = options; | ||
|
||
return useQuery({ | ||
queryKey: ['delegated-stakes', address], | ||
queryFn: () => client.getStakes({ owner: address }), | ||
...queryOptions, | ||
}); | ||
} |
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,38 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { useFormatCoin, useGetDelegatedStake } from '@mysten/core'; | ||
import { useMemo } from 'react'; | ||
import { SUI_TYPE_ARG } from '@mysten/sui.js/utils'; | ||
import { Text, Heading } from '@mysten/ui'; | ||
import { Sui } from '@mysten/icons'; | ||
|
||
export function TotalStaked({ address }: { address: string }) { | ||
const { data: delegatedStake } = useGetDelegatedStake({ | ||
address, | ||
}); | ||
|
||
// Total active stake for all delegations | ||
const totalActivePendingStake = useMemo(() => { | ||
if (!delegatedStake) return 0n; | ||
return delegatedStake.reduce( | ||
(acc, curr) => curr.stakes.reduce((total, { principal }) => total + BigInt(principal), acc), | ||
0n, | ||
); | ||
}, [delegatedStake]); | ||
|
||
const [formatted, symbol] = useFormatCoin(totalActivePendingStake, SUI_TYPE_ARG); | ||
return totalActivePendingStake ? ( | ||
<div className="flex min-w-44 items-center justify-start gap-3 rounded-xl bg-white/60 px-4 py-3 backdrop-blur-sm"> | ||
<Sui className="flex h-8 w-8 items-center justify-center rounded-full bg-sui-primaryBlue2023 py-1.5 text-white" /> | ||
<div className="flex flex-col"> | ||
<Text variant="pBody/semibold" color="steel-dark" uppercase> | ||
Staking | ||
</Text> | ||
<Heading variant="heading6/semibold" color="hero-darkest" as="div"> | ||
{formatted} {symbol} | ||
</Heading> | ||
</div> | ||
</div> | ||
) : 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
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
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.
Oops, something went wrong.
4265d4b
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-mysten-labs.vercel.app
sui-typescript-docs.vercel.app
sui-wallet-kit.vercel.app
sui-typescript-docs-git-main-mysten-labs.vercel.app
4265d4b
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.vercel.app
mysten-ui-git-main-mysten-labs.vercel.app
mysten-ui-mysten-labs.vercel.app
4265d4b
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-git-main-mysten-labs.vercel.app
explorer-topaz.vercel.app
www.suiexplorer.com
suiexplorer.com
explorer-mysten-labs.vercel.app
explorer.sui.io
www.explorer.sui.io