Skip to content

Commit 0122d44

Browse files
committed
fix: save update balances
1 parent 2aa580c commit 0122d44

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

packages/extension-polkagate/src/hooks/useAssetsBalances.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ const DEFAULT_SAVED_ASSETS = { balances: {} as AssetsBalancesPerAddress, timeSta
103103
export const ASSETS_NAME_IN_STORAGE = 'assets';
104104
const BALANCE_VALIDITY_PERIOD = 1 * 1000 * 60;
105105

106-
const isUpToDate = (date?: number): boolean | undefined => date ? Date.now() - date < BALANCE_VALIDITY_PERIOD : undefined;
106+
export const isUpToDate = (date?: number): boolean | undefined => date ? Date.now() - date < BALANCE_VALIDITY_PERIOD : undefined;
107107

108108
function allHexToBN (balances: object | string | undefined): BalancesDetails | {} {
109109
if (!balances) {

packages/extension-polkagate/src/hooks/useBalances.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { useEffect, useState } from 'react';
99

1010
import { updateMeta } from '../messaging';
1111
import { NATIVE_TOKEN_ASSET_ID, NATIVE_TOKEN_ASSET_ID_ON_ASSETHUB } from '../util/constants';
12+
import { isUpToDate } from './useAssetsBalances';
1213
import { useBalancesOnAssethub, useBalancesOnMultiAssetChain, useInfo, useNativeAssetBalances, usePoolBalances, useStakingAccount } from '.';
1314

1415
export default function useBalances (address: string | undefined, refresh?: boolean, setRefresh?: React.Dispatch<React.SetStateAction<boolean>>, onlyNew = false, assetId?: string | number): BalancesInfo | undefined {
@@ -33,7 +34,7 @@ export default function useBalances (address: string | undefined, refresh?: bool
3334
useEffect(() => {
3435
const apiGenesisHash = api?.genesisHash?.toString();
3536

36-
if (onlyNew && balances && pooledBalance && apiGenesisHash === chain?.genesisHash && apiGenesisHash === balances?.genesisHash && apiGenesisHash === pooledBalance.genesisHash) {
37+
if (balances && isUpToDate(balances?.date) && pooledBalance && apiGenesisHash === chain?.genesisHash && apiGenesisHash === balances?.genesisHash && apiGenesisHash === pooledBalance.genesisHash) {
3738
setOverall({
3839
...balances,
3940
pooledBalance: pooledBalance.balance,

0 commit comments

Comments
 (0)