Skip to content

Commit

Permalink
fix: save update balances
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick-1979 committed Oct 6, 2024
1 parent 2aa580c commit 0122d44
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const DEFAULT_SAVED_ASSETS = { balances: {} as AssetsBalancesPerAddress, timeSta
export const ASSETS_NAME_IN_STORAGE = 'assets';
const BALANCE_VALIDITY_PERIOD = 1 * 1000 * 60;

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

function allHexToBN (balances: object | string | undefined): BalancesDetails | {} {
if (!balances) {
Expand Down
3 changes: 2 additions & 1 deletion packages/extension-polkagate/src/hooks/useBalances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useEffect, useState } from 'react';

import { updateMeta } from '../messaging';
import { NATIVE_TOKEN_ASSET_ID, NATIVE_TOKEN_ASSET_ID_ON_ASSETHUB } from '../util/constants';
import { isUpToDate } from './useAssetsBalances';
import { useBalancesOnAssethub, useBalancesOnMultiAssetChain, useInfo, useNativeAssetBalances, usePoolBalances, useStakingAccount } from '.';

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

if (onlyNew && balances && pooledBalance && apiGenesisHash === chain?.genesisHash && apiGenesisHash === balances?.genesisHash && apiGenesisHash === pooledBalance.genesisHash) {
if (balances && isUpToDate(balances?.date) && pooledBalance && apiGenesisHash === chain?.genesisHash && apiGenesisHash === balances?.genesisHash && apiGenesisHash === pooledBalance.genesisHash) {
setOverall({
...balances,
pooledBalance: pooledBalance.balance,
Expand Down

0 comments on commit 0122d44

Please sign in to comment.