Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use scale api only for bittensor balance rows #1740

Merged
merged 4 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions apps/extension/src/ui/domains/Staking/Bond/useBondButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ export const useBondButton = ({

const address = sorted[0]?.address

const { data: hotkeys } = useGetBittensorStakeHotkeys({
chainId: token?.chain?.id,
address,
})
const { data: hotkeys } = useGetBittensorStakeHotkeys({ chainId: token?.chain?.id, address })

const [openArgs, isNomPoolStaking] = useMemo<[Parameters<typeof open>[0] | null, boolean]>(() => {
if (!balances || !tokenId || !token?.chain || token?.type !== "substrate-native")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export const useGetBittensorStakeHotkeys = ({
address,
totalStaked,
}: GetBittensorStakeHotkeys) => {
const { data: sapi } = useScaleApi(chainId)
// this calls useScaleApi which downloads metadata from chain, we only want this to be done for bittensor
const { data: sapi } = useScaleApi(chainId === "bittensor" ? "bittensor" : null)

return useQuery({
queryKey: ["getBittensorStakeHotkeys", sapi?.id, address, totalStaked],
Expand Down
5 changes: 5 additions & 0 deletions apps/extension/src/ui/hooks/sapi/useScaleApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import { api } from "@ui/api"
import { useChain, useChainByGenesisHash, useToken } from "@ui/state"
import { getScaleApi, ScaleApi } from "@ui/util/scaleApi"

/**
* useScaleApi instantiates a ScaleApi object for a given chainIdOrHash, specVersion, and blockHash.
* Calling this hook will download the metadata for the given chainIdOrHash, which can cause performance issues.
* It is recommended to use this hook only when necessary and not in a loop where it may be called many times for many chains.
*/
export const useScaleApi = (
chainIdOrHash: ChainId | HexString | null | undefined,
specVersion?: number,
Expand Down
Loading