From 3285fb9149dd3219f809c71ba2c922d7ec9f4ae1 Mon Sep 17 00:00:00 2001 From: Peiman <25097709+Rickk137@users.noreply.github.com> Date: Wed, 22 May 2024 12:32:55 +0330 Subject: [PATCH] fix: account id update issue (#277) --- .../AccountsSelector/AccountsSelector.tsx | 1 - .../src/layouts/Default/NetworkController.tsx | 17 ++++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/liquidity/components/AccountsSelector/AccountsSelector.tsx b/liquidity/components/AccountsSelector/AccountsSelector.tsx index 95268b71a..f49046131 100644 --- a/liquidity/components/AccountsSelector/AccountsSelector.tsx +++ b/liquidity/components/AccountsSelector/AccountsSelector.tsx @@ -64,7 +64,6 @@ export function AccountsSelectorUi({ return ( <> - {/* // Temporarily disable account selector menu */} {isLoading ? ( diff --git a/liquidity/ui/src/layouts/Default/NetworkController.tsx b/liquidity/ui/src/layouts/Default/NetworkController.tsx index f1da95bde..cf0068011 100644 --- a/liquidity/ui/src/layouts/Default/NetworkController.tsx +++ b/liquidity/ui/src/layouts/Default/NetworkController.tsx @@ -26,13 +26,28 @@ export function NetworkController() { const [toolTipLabel, setTooltipLabel] = useState('Copy'); const { activeWallet, walletsInfo, connect, disconnect } = useWallet(); const { network: activeNetwork, setNetwork } = useNetwork(); - const { data: accounts } = useAccounts(); + const { + data: accounts, + isLoading: isAccountsLoading, + isFetching: isAccountsFetching, + } = useAccounts(); const { mutation } = useCreateAccount(); const [showTestnets, setShowTestnets] = useLocalStorage(LOCAL_STORAGE_KEYS.SHOW_TESTNETS, false); const [queryParams] = useSearchParams(); const navigate = useNavigate(); const { pathname } = useLocation(); + useEffect(() => { + if (!isAccountsLoading && !isAccountsFetching && accounts) { + const accountId = queryParams.get('accountId'); + + if (accountId && !accounts?.includes(accountId)) { + queryParams.set('accountId', accounts[0]); + navigate({ pathname, search: accounts[0] ? queryParams.toString() : '' }); + } + } + }, [accounts, isAccountsLoading, isAccountsFetching, queryParams, navigate, pathname]); + useEffect(() => { // Check if wallet preference is stored in local storage if (!walletsInfo) {