Skip to content

Commit

Permalink
Merge pull request #189 from alephium/add-refresh-button
Browse files Browse the repository at this point in the history
Add Refresh Token Button
  • Loading branch information
h0ngcha0 authored Apr 20, 2024
2 parents 1379f9a + e71d227 commit cc65e8b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { H2 } from "@argent/ui"
import { VStack } from "@chakra-ui/react"
import { H2, Button } from "@argent/ui"
import { VStack, Flex } from "@chakra-ui/react"
import { FC } from "react"

import { prettifyCurrencyValue } from "../../../shared/token/price"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ALPH_TOKEN_ID, NodeProvider } from "@alephium/web3"
import { BigNumber } from "ethers"
import { memoize } from "lodash-es"
import { useEffect, useMemo, useRef } from "react"
import useSWR from "swr"
import useSWR, { KeyedMutator } from "swr"
import { getNetwork, Network } from "../../../shared/network"

import { useArrayStorage, useObjectStorage } from "../../../shared/storage/hooks"
Expand All @@ -25,6 +25,7 @@ interface UseTokensBase<T> {
tokenDetails: T[]
tokenDetailsIsInitialising: boolean
isValidating: boolean
mutate: KeyedMutator<T[] | undefined> | KeyedMutator<T[]>
error?: any
}

Expand Down Expand Up @@ -169,6 +170,7 @@ export const useFungibleTokensWithBalance = (
const {
data: fungibleTokens,
isValidating,
mutate,
error
} = useSWR(
account && [
Expand Down Expand Up @@ -216,7 +218,8 @@ export const useFungibleTokensWithBalance = (
tokenDetails: fungibleTokens || [],
tokenDetailsIsInitialising: allUserTokensIsInitialising && tokenDetailsIsInitialising,
isValidating: allUserTokensIsValidating || isValidating,
error: allUserTokensError || error
error: allUserTokensError || error,
mutate
}
}

Expand Down Expand Up @@ -297,6 +300,7 @@ export const useAllTokensWithBalance = (
tokenDetails: userTokens || [],
tokenDetailsIsInitialising,
isValidating,
mutate,
error,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { routes, useCurrentPathnameWithQuery } from "../../routes"
import { NetworkSwitcher } from "../networks/NetworkSwitcher"
import { getAccountName, useAccountMetadata } from "./accountMetadata.state"
import { Account } from "../accounts/Account"
import { SyncRounded } from "@mui/icons-material"
import { useFungibleTokensWithBalance } from "../accountTokens/tokens.state"

const { SettingsIcon, DropdownDownIcon } = icons

Expand All @@ -30,7 +32,7 @@ export const AccountNavigationBar: FC<AccountNavigationBarProps> = ({
const navigate = useNavigate()
const location = useLocation()
const returnTo = useCurrentPathnameWithQuery()

const { mutate } = useFungibleTokensWithBalance(account)
const openAccountList = useCallback(() => {
navigate(routes.accounts(location.pathname))
}, [location.pathname, navigate])
Expand All @@ -57,6 +59,14 @@ export const AccountNavigationBar: FC<AccountNavigationBarProps> = ({
</Text>
</Button>
)}
<BarIconButton
ml={1}
aria-label="Sync account"
onClick={() => { mutate() }}
colorScheme={"neutrals"}
>
<SyncRounded fontSize="small"/>
</BarIconButton>
<Flex ml={"auto"}>
<NetworkSwitcher />
<BarIconButton
Expand Down

0 comments on commit cc65e8b

Please sign in to comment.