Skip to content

Commit 2617df8

Browse files
committed
frontend: use navigate instead of route
The route component was added so that class based components can keep using route function. Once all components are functional components route utils function can be removed.
1 parent 39f90f8 commit 2617df8

File tree

21 files changed

+81
-56
lines changed

21 files changed

+81
-56
lines changed

frontends/web/src/routes/account/add/add.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
import React, { useCallback, useEffect, useRef, useState } from 'react';
18+
import { useNavigate } from 'react-router-dom';
1819
import { useTranslation } from 'react-i18next';
1920
import * as backendAPI from '@/api/backend';
2021
import * as keystoresAPI from '@/api/keystores';
@@ -26,7 +27,6 @@ import { Step, Steps } from './components/steps';
2627
import { CoinDropDown } from './components/coin-dropdown';
2728
import { Check } from '@/components/icon/icon';
2829
import { AddAccountGuide } from './add-account-guide';
29-
import { route } from '@/utils/route';
3030
import { addAccount, CoinCode, TAddAccount, IAccount } from '@/api/account';
3131
import styles from './add.module.css';
3232

@@ -37,6 +37,7 @@ type TAddAccountGuide = {
3737
type TStep = 'select-coin' | 'choose-name' | 'success';
3838

3939
export const AddAccount = ({ accounts }: TAddAccountGuide) => {
40+
const navigate = useNavigate();
4041
const [accountCode, setAccountCode] = useState<string>();
4142
const [accountName, setAccountName] = useState('');
4243
const [coinCode, setCoinCode] = useState<'choose' | CoinCode>('choose');
@@ -87,7 +88,7 @@ export const AddAccount = ({ accounts }: TAddAccountGuide) => {
8788
const back = () => {
8889
switch (step) {
8990
case 'select-coin':
90-
route('/settings/manage-accounts');
91+
navigate('/settings/manage-accounts');
9192
break;
9293
case 'choose-name':
9394
setStep('select-coin');
@@ -122,7 +123,7 @@ export const AddAccount = ({ accounts }: TAddAccountGuide) => {
122123
break;
123124
case 'success':
124125
if (accountCode) {
125-
route(`/account/${accountCode}`);
126+
navigate(`/account/${accountCode}`);
126127
}
127128
break;
128129
}

frontends/web/src/routes/account/info/info.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
*/
1717

1818
import { useState } from 'react';
19+
import { useNavigate } from 'react-router-dom';
1920
import { useTranslation } from 'react-i18next';
2021
import { useLoad } from '@/hooks/api';
2122
import { useEsc } from '@/hooks/keyboard';
2223
import { getInfo, IAccount, AccountCode } from '@/api/account';
23-
import { route } from '@/utils/route';
2424
import { isBitcoinBased } from '@/routes/account/utils';
2525
import { ButtonLink } from '@/components/forms';
2626
import { Header } from '@/components/layout';
@@ -37,12 +37,13 @@ export const Info = ({
3737
accounts,
3838
code,
3939
}: TProps) => {
40+
const navigate = useNavigate();
4041
const { t } = useTranslation();
4142
const info = useLoad(getInfo(code));
4243
const [viewXPub, setViewXPub] = useState<number>(0);
4344
const account = accounts.find(({ code: accountCode }) => accountCode === code);
4445

45-
useEsc(() => route(`/account/${code}`));
46+
useEsc(() => navigate(`/account/${code}`));
4647

4748
if (!account || !info) {
4849
return null;

frontends/web/src/routes/account/info/signingconfiguration.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
*/
1717

1818
import { useState, ReactNode } from 'react';
19+
import { useNavigate } from 'react-router-dom';
1920
import { useTranslation } from 'react-i18next';
20-
import { route } from '@/utils/route';
2121
import { AccountCode, IAccount, TBitcoinSimple, TEthereumSimple, TSigningConfiguration, verifyXPub } from '@/api/account';
2222
import { getScriptName, isBitcoinBased } from '@/routes/account/utils';
2323
import { alertUser } from '@/components/alert/Alert';
@@ -35,6 +35,7 @@ type TProps = {
3535
}
3636

3737
export const SigningConfiguration = ({ account, info, code, signingConfigIndex, children }: TProps) => {
38+
const navigate = useNavigate();
3839
const { t } = useTranslation();
3940
const [verifying, setVerifying] = useState(false);
4041

@@ -111,7 +112,7 @@ export const SigningConfiguration = ({ account, info, code, signingConfigIndex,
111112
{t('accountInfo.verify')}
112113
</Button>
113114
) : (
114-
<Button className={style.verifyButton} primary onClick={() => route(`/account/${code}/receive`)}>
115+
<Button className={style.verifyButton} primary onClick={() => navigate(`/account/${code}/receive`)}>
115116
{t('receive.verify')}
116117
</Button>
117118
) }

frontends/web/src/routes/account/receive/receive-bb01.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
*/
1717

1818
import React, { useEffect, useRef, useState } from 'react';
19+
import { useNavigate } from 'react-router-dom';
1920
import { useTranslation } from 'react-i18next';
2021
import { useLoad } from '@/hooks/api';
2122
import { useEsc } from '@/hooks/keyboard';
2223
import * as accountApi from '@/api/account';
23-
import { route } from '@/utils/route';
2424
import { getScriptName, isEthereumBased } from '@/routes/account/utils';
2525
import { alertUser } from '@/components/alert/Alert';
2626
import { CopyableInput } from '@/components/copy/Copy';
@@ -63,6 +63,7 @@ export const Receive = ({
6363
code,
6464
deviceID,
6565
}: TProps) => {
66+
const navigate = useNavigate();
6667
const { t } = useTranslation();
6768
const [verifying, setVerifying] = useState<boolean>(false);
6869
const [activeIndex, setActiveIndex] = useState<number>(0);
@@ -79,7 +80,7 @@ export const Receive = ({
7980
const receiveAddresses = useLoad(accountApi.getReceiveAddressList(code));
8081
const secureOutput = useLoad(accountApi.hasSecureOutput(code));
8182

82-
useEsc(() => !verifying && route(`/account/${code}`));
83+
useEsc(() => !verifying && navigate(`/account/${code}`));
8384

8485
const availableScriptTypes = useRef<accountApi.ScriptType[]>();
8586

frontends/web/src/routes/account/receive/receive.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
*/
1717

1818
import React, { useEffect, useRef, useState } from 'react';
19+
import { useNavigate } from 'react-router-dom';
1920
import { useTranslation } from 'react-i18next';
2021
import { useLoad } from '@/hooks/api';
2122
import { useEsc } from '@/hooks/keyboard';
2223
import * as accountApi from '@/api/account';
23-
import { route } from '@/utils/route';
2424
import { getScriptName, isEthereumBased } from '@/routes/account/utils';
2525
import { CopyableInput } from '@/components/copy/Copy';
2626
import { Dialog, DialogButtons } from '@/components/dialog/dialog';
@@ -114,6 +114,7 @@ export const Receive = ({
114114
accounts,
115115
code,
116116
}: TProps) => {
117+
const navigate = useNavigate();
117118
const { t } = useTranslation();
118119
const [verifying, setVerifying] = useState<false | 'secure' | 'insecure'>(false);
119120
const [activeIndex, setActiveIndex] = useState<number>(0);
@@ -133,7 +134,7 @@ export const Receive = ({
133134

134135
const hasManyScriptTypes = availableScriptTypes.current && availableScriptTypes.current.length > 1;
135136

136-
useEsc(() => !addressTypeDialog && !verifying && route(`/account/${code}`));
137+
useEsc(() => !addressTypeDialog && !verifying && navigate(`/account/${code}`));
137138

138139
useEffect(() => {
139140
if (receiveAddresses) {

frontends/web/src/routes/account/summary/balancerow.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
* limitations under the License.
1515
*/
1616

17+
import { useNavigate } from 'react-router-dom';
1718
import { useTranslation } from 'react-i18next';
1819
import { AccountCode, CoinCode, IBalance } from '@/api/account';
1920
import { syncAddressesCount } from '@/api/accountsync';
2021
import { useSubscribe } from '@/hooks/api';
21-
import { route } from '@/utils/route';
2222
import { Logo } from '@/components/icon/logo';
2323
import { Amount } from '@/components/amount/amount';
2424
import { AsciiSpinner } from '@/components/spinner/ascii';
@@ -35,14 +35,15 @@ type TProps = {
3535
export const BalanceRow = (
3636
{ code, name, coinCode, balance }: TProps
3737
) => {
38+
const navigate = useNavigate();
3839
const { t } = useTranslation();
3940
const syncStatus = useSubscribe(syncAddressesCount(code));
4041

4142
const nameCol = (
4243
<td
4344
className={style.clickable}
4445
data-label={t('accountSummary.name')}
45-
onClick={() => route(`/account/${code}`)}>
46+
onClick={() => navigate(`/account/${code}`)}>
4647
<div className={style.coinName}>
4748
<Logo className={style.coincode} coinCode={coinCode} active={true} alt={coinCode} />
4849
{name}

frontends/web/src/routes/account/walletconnect/components/connect-form/connect-form.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
*/
1616

1717
import { SetStateAction, useState } from 'react';
18+
import { useNavigate } from 'react-router-dom';
1819
import { useTranslation } from 'react-i18next';
1920
import * as accountAPI from '@/api/account';
2021
import { Button, Input } from '@/components/forms';
21-
import { route } from '@/utils/route';
2222
import { useMediaQuery } from '@/hooks/mediaquery';
2323
import { ScanQRButton } from '@/routes/account/send/components/inputs/receiver-address-input';
2424
import { ScanQRDialog } from '@/routes/account/send/components/dialogs/scan-qr-dialog';
@@ -52,6 +52,7 @@ export const WCConnectForm = ({
5252
onSubmit,
5353
connectLoading
5454
}: TWCConnectFormProps) => {
55+
const navigate = useNavigate();
5556
const { t } = useTranslation();
5657
const isMobile = useMediaQuery('(max-width: 768px)');
5758
const [activeScanQR, setActiveScanQR] = useState(isMobile); // default to true on mobile
@@ -95,7 +96,7 @@ export const WCConnectForm = ({
9596
<Button
9697
disabled={connectLoading}
9798
secondary
98-
onClick={() => route(`/account/${code}/wallet-connect/dashboard`)}>
99+
onClick={() => navigate(`/account/${code}/wallet-connect/dashboard`)}>
99100
{t('dialog.cancel')}
100101
</Button>
101102
<Button

frontends/web/src/routes/account/walletconnect/components/success-pairing/success-pairing.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,26 @@
1616
*/
1717

1818
import { useTranslation } from 'react-i18next';
19+
import { useNavigate } from 'react-router-dom';
1920
import * as accountAPI from '@/api/account';
2021
import { Button } from '@/components/forms';
2122
import { AnimatedChecked } from '@/components/icon';
22-
import { route } from '@/utils/route';
2323
import styles from './success-pairing.module.css';
2424

2525
type TProps = {
2626
accountCode: accountAPI.AccountCode;
2727
}
2828

2929
export const WCSuccessPairing = ({ accountCode }: TProps) => {
30+
const navigate = useNavigate();
3031
const { t } = useTranslation();
3132
return (
3233
<div className={styles.container}>
3334
<AnimatedChecked className={styles.successIcon} />
3435
<p className={styles.successText}>{t('walletConnect.pairingSuccess')}</p>
35-
<Button primary onClick={() => route(`/account/${accountCode}/wallet-connect/dashboard`)}>{t('button.done')}</Button>
36+
<Button primary onClick={() => navigate(`/account/${accountCode}/wallet-connect/dashboard`)}>
37+
{t('button.done')}
38+
</Button>
3639
</div>
3740
);
3841
};

frontends/web/src/routes/account/walletconnect/dashboard.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
*/
1616

1717
import { useCallback, useContext, useEffect, useState } from 'react';
18+
import { useNavigate } from 'react-router-dom';
1819
import { useTranslation } from 'react-i18next';
1920
import { useLoad } from '@/hooks/api';
2021
import { SessionTypes } from '@walletconnect/types';
2122
import { getSdkError } from '@walletconnect/utils';
2223
import { WCWeb3WalletContext } from '@/contexts/WCWeb3WalletContext';
23-
import { route } from '@/utils/route';
2424
import { getAddressFromEIPString, truncateAddress } from '@/utils/walletconnect';
2525
import { AccountCode, IAccount, getReceiveAddressList } from '@/api/account';
2626
import { GuideWrapper, GuidedContent, Header, Main } from '@/components/layout';
@@ -37,6 +37,7 @@ type TProps = {
3737
}
3838

3939
export const DashboardWalletConnect = ({ code, accounts }: TProps) => {
40+
const navigate = useNavigate();
4041
const { t } = useTranslation();
4142
const { web3wallet, isWalletInitialized, initializeWeb3Wallet } = useContext(WCWeb3WalletContext);
4243
const [sessions, setSessions] = useState<SessionTypes.Struct[]>();
@@ -100,7 +101,9 @@ export const DashboardWalletConnect = ({ code, accounts }: TProps) => {
100101
<p>{accountName}</p>
101102
<p className={styles.receiveAddress}>{receiveAddress}</p>
102103
</div>
103-
<Button className={styles.buttonNewConnection} onClick={() => route(`/account/${code}/wallet-connect/connect`)} primary>{t('walletConnect.dashboard.newConnection')}</Button>
104+
<Button className={styles.buttonNewConnection} onClick={() => navigate(`/account/${code}/wallet-connect/connect`)} primary>
105+
{t('walletConnect.dashboard.newConnection')}
106+
</Button>
104107
</div>
105108
<hr className={styles.separator} />
106109
{hasSession &&

frontends/web/src/routes/accounts/select-receive.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
*/
1616

1717
import { useState } from 'react';
18+
import { useNavigate } from 'react-router-dom';
1819
import { useTranslation } from 'react-i18next';
1920
import { IAccount } from '@/api/account';
2021
import { Header } from '@/components/layout';
21-
import { route } from '@/utils/route';
2222
import { isBitcoinOnly } from '@/routes/account/utils';
2323
import { View, ViewContent } from '@/components/view/view';
2424
import { GroupedAccountSelector } from '@/components/groupedaccountselector/groupedaccountselector';
@@ -27,11 +27,12 @@ type TReceiveAccountsSelector = {
2727
activeAccounts: IAccount[]
2828
}
2929
export const ReceiveAccountsSelector = ({ activeAccounts }: TReceiveAccountsSelector) => {
30-
const [code, setCode] = useState('');
30+
const navigate = useNavigate();
3131
const { t } = useTranslation();
32+
const [code, setCode] = useState('');
3233

3334
const handleProceed = () => {
34-
route(`/account/${code}/receive`);
35+
navigate(`/account/${code}/receive`);
3536
};
3637

3738
const hasOnlyBTCAccounts = activeAccounts.every(({ coinCode }) => isBitcoinOnly(coinCode));

0 commit comments

Comments
 (0)