Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [ADN-409] Fix Cannot Sign Transaction popup #362

Merged
merged 2 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const WalletProvider: React.FC<React.PropsWithChildren<unknown>> = ({ chi
}, []);

useEffect(() => {
if (wallet && networkMetainfos && tokenMetainfos) {
if (wallet && networkMetainfos.length > 0 && tokenMetainfos.length > 0) {
setWalletStatus('FINISH');
}
}, [wallet, networkMetainfos, tokenMetainfos]);
Expand All @@ -75,6 +75,9 @@ export const WalletProvider: React.FC<React.PropsWithChildren<unknown>> = ({ chi
setWalletStatus('LOADING');
try {
const wallet = await walletService.loadWallet();
console.log(wallet);
jinoosss marked this conversation as resolved.
Show resolved Hide resolved
const currentAccountId = await accountService.getCurrentAccountId();
wallet.currentAccountId = currentAccountId;
setWallet(wallet);
await initCurrentAccount(wallet);
} catch (e) {
Expand Down
2 changes: 0 additions & 2 deletions packages/adena-extension/src/hooks/use-current-account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ export const useCurrentAccount = (): {
return false;
}
await accountService.changeCurrentAccount(changedAccount);
const clone = wallet.clone();
clone.currentAccountId = changedAccount.id;
setCurrentAccount(changedAccount);
dispatchChangedEvent(changedAccount);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export const useRemoveAccount = (): {
clone.removeAccount(account);
const nextAccount = clone.accounts[clone.accounts.length - 1];
clone.currentAccountId = nextAccount.id;
await updateWallet(clone);
await changeCurrentAccount(nextAccount);
await updateWallet(clone);
return true;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@ const useGoogleLoginScreen = (): UseGoogleLoginReturn => {
const web3AuthKeyring = await Web3AuthKeyring.fromPrivateKeyStr(privateKey);
const account = await SingleAccount.createBy(web3AuthKeyring, clone.nextAccountName);
clone.addAccount(account);
await changeCurrentAccount(account);
clone.addKeyring(web3AuthKeyring);
const storedAccount = clone.accounts.find((storedAccount) => storedAccount.id === account.id);
if (storedAccount) {
await changeCurrentAccount(storedAccount);
}
await updateWallet(clone);
navigate(RoutePath.WebAccountAddedComplete);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@ const useSetupAirgapScreen = (): UseSetupAirgapScreenReturn => {
const clone = wallet.clone();
clone.addAccount(account);
clone.addKeyring(addressKeyring);

await changeCurrentAccount(account);
const storedAccount = clone.accounts.find((storedAccount) => storedAccount.id === account.id);
if (storedAccount) {
await changeCurrentAccount(storedAccount);
}
await updateWallet(clone);
navigate(RoutePath.WebAccountAddedComplete);
}, [address, walletService]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,11 @@ const useAccountImportScreen = ({ wallet }: { wallet: Wallet }): UseAccountImpor
const clone = wallet.clone();
clone.addAccount(account);
clone.addKeyring(keyring);

const storedAccount = clone.accounts.find((storedAccount) => storedAccount.id === account.id);
if (storedAccount) {
await changeCurrentAccount(storedAccount);
}
await updateWallet(clone);
await changeCurrentAccount(account);
navigate(RoutePath.WebAccountAddedComplete);
}
}, [step, privateKey, ableToSkipQuestionnaire, makePrivateKeyAccountAndKeyring]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,13 @@ const useWalletCreateScreen = (): UseWalletCreateReturn => {
const clone = wallet.clone();
clone.addAccount(account);
clone.addKeyring(keyring);
const storedAccount = clone.accounts.find(
(storedAccount) => storedAccount.id === account.id,
);
if (storedAccount) {
await changeCurrentAccount(storedAccount);
}
await updateWallet(clone);
await changeCurrentAccount(account);
navigate(RoutePath.WebAccountAddedComplete);
} else {
const createdWallet = await AdenaWallet.createByMnemonic(seeds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const RemoveAccount = (): JSX.Element => {
}
setState('LOADING');
await removeAccount(currentAccount);
navigate(RoutePath.Home);
navigate(RoutePath.Wallet);
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import AccountDetails from '@components/pages/account-details/account-details';
import { useLoadAccounts } from '@hooks/use-load-accounts';
import { useNetwork } from '@hooks/use-network';
import { useAccountName } from '@hooks/use-account-name';
import { useCurrentAccount } from '@hooks/use-current-account';
import { CommonFullContentLayout } from '@components/atoms';
import useLink from '@hooks/use-link';
import { AdenaStorage } from '@common/storage';
Expand All @@ -20,7 +19,6 @@ const AccountDetailsContainer: React.FC = () => {
const { accounts } = useLoadAccounts();
const { currentNetwork } = useNetwork();
const { accountNames, changeAccountName } = useAccountName();
const { changeCurrentAccount } = useCurrentAccount();
const [originName, setOriginName] = useState('');
const [name, setName] = useState('');
const [address, setAddress] = useState<string>('');
Expand Down Expand Up @@ -55,9 +53,6 @@ const AccountDetailsContainer: React.FC = () => {
}, [address]);

const moveExportPrivateKey = useCallback(async () => {
if (account) {
await changeCurrentAccount(account);
}
const sessionStorage = AdenaStorage.session();
await sessionStorage.set(WALLET_EXPORT_TYPE_STORAGE_KEY, 'PRIVATE_KEY');
openSecurity();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,17 @@ export const WalletCreate = (): JSX.Element => {
useEffect(() => {
switch (state) {
case 'NONE':
case 'LOADING':
break;
case 'CREATE':
case 'FAIL':
openRegister();
break;
case 'LOADING':
navigate(RoutePath.Wallet);
break;
case 'LOGIN':
navigate(RoutePath.Login);
break;
default:
navigate(RoutePath.Wallet);
break;
}
}, [state]);
Expand Down
Loading