mirror of
https://github.com/zhigang1992/xverse-web-extension.git
synced 2026-01-12 22:53:42 +08:00
Merge branch 'develop' into denys/eng-3455-fix-the-sharp-fee-change-on-tx-confirmation
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
import { PropsWithChildren, useEffect } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import useSeedVault from '@hooks/useSeedVault';
|
||||
import useWalletSelector from '@hooks/useWalletSelector';
|
||||
import { useDispatch } from 'react-redux';
|
||||
import { setWalletUnlockedAction } from '@stores/wallet/actions/actionCreators';
|
||||
import { PropsWithChildren, useEffect } from 'react';
|
||||
import { useDispatch } from 'react-redux';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
|
||||
function AuthGuard({ children }: PropsWithChildren) {
|
||||
const navigate = useNavigate();
|
||||
const { masterPubKey, encryptedSeed, isUnlocked } = useWalletSelector();
|
||||
const { masterPubKey, encryptedSeed, isUnlocked, accountsList } = useWalletSelector();
|
||||
const { getSeed, hasSeed } = useSeedVault();
|
||||
const dispatch = useDispatch();
|
||||
|
||||
@@ -26,7 +26,12 @@ function AuthGuard({ children }: PropsWithChildren) {
|
||||
return;
|
||||
}
|
||||
const hasSeedPhrase = await hasSeed();
|
||||
if (!hasSeedPhrase || !masterPubKey) {
|
||||
if (
|
||||
!hasSeedPhrase ||
|
||||
// We ensure there is at least 1 account with a masterPubKey as the unlock code will select an account if one
|
||||
// is not selected in the store
|
||||
(!masterPubKey && (accountsList.length === 0 || !accountsList[0].masterPubKey))
|
||||
) {
|
||||
navigate('/landing');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -65,6 +65,7 @@ const useWalletReducer = () => {
|
||||
currentAccounts,
|
||||
);
|
||||
|
||||
// we sanitise the account to remove any unknown properties which we had in pervious versions of the app
|
||||
walletAccounts[0] = {
|
||||
id: walletAccounts[0].id,
|
||||
btcAddress: walletAccounts[0].btcAddress,
|
||||
@@ -77,13 +78,18 @@ const useWalletReducer = () => {
|
||||
bnsName: walletAccounts[0].bnsName,
|
||||
};
|
||||
|
||||
let selectedAccountData: Account;
|
||||
let selectedAccountData: Account | undefined;
|
||||
if (!selectedAccount) {
|
||||
[selectedAccountData] = walletAccounts;
|
||||
} else if (isLedgerAccount(selectedAccount)) {
|
||||
selectedAccountData = ledgerAccountsList[selectedAccount.id];
|
||||
selectedAccountData = ledgerAccountsList.find((a) => a.id === selectedAccount.id);
|
||||
} else {
|
||||
selectedAccountData = walletAccounts[selectedAccount.id];
|
||||
selectedAccountData = walletAccounts.find((a) => a.id === selectedAccount.id);
|
||||
}
|
||||
|
||||
if (!selectedAccountData) {
|
||||
// this should not happen but is a good fallback to have, just in case
|
||||
[selectedAccountData] = walletAccounts;
|
||||
}
|
||||
|
||||
if (!isHardwareAccount(selectedAccountData)) {
|
||||
@@ -326,37 +332,25 @@ const useWalletReducer = () => {
|
||||
};
|
||||
|
||||
const addLedgerAccount = async (ledgerAccount: Account) => {
|
||||
try {
|
||||
dispatch(updateLedgerAccountsAction([...ledgerAccountsList, ledgerAccount]));
|
||||
} catch (err) {
|
||||
return Promise.reject(err);
|
||||
}
|
||||
};
|
||||
|
||||
const removeLedgerAccount = async (ledgerAccount: Account) => {
|
||||
try {
|
||||
dispatch(
|
||||
updateLedgerAccountsAction(
|
||||
ledgerAccountsList.filter((account) => account.id !== ledgerAccount.id),
|
||||
),
|
||||
);
|
||||
} catch (err) {
|
||||
return Promise.reject(err);
|
||||
}
|
||||
};
|
||||
|
||||
const updateLedgerAccounts = async (updatedLedgerAccount: Account) => {
|
||||
const newLedgerAccountsList = ledgerAccountsList.map((account) =>
|
||||
account.id === updatedLedgerAccount.id ? updatedLedgerAccount : account,
|
||||
);
|
||||
try {
|
||||
dispatch(updateLedgerAccountsAction(newLedgerAccountsList));
|
||||
if (isLedgerAccount(selectedAccount) && updatedLedgerAccount.id === selectedAccount?.id) {
|
||||
switchAccount(updatedLedgerAccount);
|
||||
}
|
||||
} catch (err) {
|
||||
return Promise.reject(err);
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user