Update tx state accounts on delete account.

This commit is contained in:
muzam1l
2022-08-02 15:23:11 +05:30
parent 6ee1a09aaa
commit 7f6b989f15
3 changed files with 27 additions and 5 deletions

View File

@@ -32,6 +32,7 @@ import { SetHookDialog } from "./SetHookDialog";
import { addFunds } from "../state/actions/addFaucetAccount";
import { deleteHook } from "../state/actions/deployHook";
import { capitalize } from "../utils/helpers";
import { deleteAccount } from '../state/actions/deleteAccount';
export const AccountDialog = ({
activeAccountAddress,
@@ -99,10 +100,7 @@ export const AccountDialog = ({
css={{ ml: "auto", mr: "$9" }}
tabIndex={-1}
onClick={() => {
const index = state.accounts.findIndex(
acc => acc.address === activeAccount?.address
);
state.accounts.splice(index, 1);
deleteAccount(activeAccount?.address);
}}
>
Delete Account <Trash size="15px" />

View File

@@ -162,7 +162,7 @@ export const Log: FC<ILog> = ({
const enrichAccounts = useCallback(
(str?: string): ReactNode => {
if (!str || !accounts.length) return null;
if (!str || !accounts.length) return str;
const pattern = `(${accounts.map(acc => acc.address).join("|")})`;
const res = regexifyString({

View File

@@ -0,0 +1,24 @@
import state, { transactionsState } from '..';
export const deleteAccount = (addr?: string) => {
if (!addr) return;
const index = state.accounts.findIndex(acc => acc.address === addr);
if (index === -1) return;
state.accounts.splice(index, 1);
// update selected accounts
transactionsState.transactions
.filter(t => t.state.selectedAccount?.value === addr)
.forEach(t => {
const acc = t.state.selectedAccount;
if (!acc) return;
acc.label = acc.value;
});
transactionsState.transactions
.filter(t => t.state.selectedDestAccount?.value === addr)
.forEach(t => {
const acc = t.state.selectedDestAccount;
if (!acc) return;
acc.label = acc.value;
});
};