Compare commits

..

1 Commits

Author SHA1 Message Date
muzam1l
7f6b989f15 Update tx state accounts on delete account. 2022-08-02 15:23:11 +05:30
8 changed files with 66 additions and 64 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

@@ -24,19 +24,13 @@ import { saveAllFiles } from "../state/actions/saveFile";
import { Tab, Tabs } from "./Tabs";
import { renameFile } from "../state/actions/createNewFile";
const checkWritable = (filename?: string): boolean => {
if (apiHeaderFiles.find(file => file === filename)) {
return false;
const validateWritability = (editor: monaco.editor.IStandaloneCodeEditor) => {
const currPath = editor.getModel()?.uri.path;
if (apiHeaderFiles.find(h => currPath?.endsWith(h))) {
editor.updateOptions({ readOnly: true });
} else {
editor.updateOptions({ readOnly: false });
}
return true;
};
const validateWritability = (
editor: monaco.editor.IStandaloneCodeEditor
) => {
const filename = editor.getModel()?.uri.path.split("/").pop();
const isWritable = checkWritable(filename);
editor.updateOptions({ readOnly: !isWritable });
};
let decorations: { [key: string]: string[] } = {};
@@ -144,7 +138,7 @@ const HooksEditor = () => {
}}
>
{snap.files.map((file, index) => {
return <Tab key={file.name} header={file.name} renameDisabled={!checkWritable(file.name)} />;
return <Tab key={file.name} header={file.name} />;
})}
</Tabs>
);

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

@@ -143,6 +143,7 @@ const RunScript: React.FC<{ file: IFile }> = ({ file: { content, name } }) => {
setIframeCode(template);
state.scriptLogs = [
...snap.scriptLogs,
{ type: "success", message: "Started running..." },
];
} catch (err) {

View File

@@ -31,7 +31,6 @@ type Nullable<T> = T | null | undefined | false;
interface TabProps {
header: string;
children?: ReactNode;
renameDisabled?: boolean
}
// TODO customize messages shown
@@ -99,15 +98,16 @@ export const Tabs = ({
}, [tabname, setTabnameError]);
const validateTabname = useCallback(
(tabname: string): { error?: string; result?: string } => {
(tabname: string): { error?: string, result?: string } => {
if (!tabname) {
return { error: `Please enter ${label.toLocaleLowerCase()} name.` };
}
let ext = (tabname.includes(".") && tabname.split(".").pop()) || "";
let ext =
(tabname.includes(".") && tabname.split(".").pop()) || "";
if (!ext && defaultExtension) {
ext = defaultExtension;
tabname = `${tabname}.${defaultExtension}`;
ext = defaultExtension
tabname = `${tabname}.${defaultExtension}`
}
if (tabs.find(tab => tab.header === tabname)) {
return { error: `${capitalize(label)} name already exists.` };
@@ -153,23 +153,16 @@ export const Tabs = ({
return;
}
const { result: nwName = tabname } = res;
const { result: _tabname = tabname } = res
setRenamingTab(null);
setTabname("");
const oldName = tabs[renamingTab]?.header;
onRenameTab?.(renamingTab, nwName, oldName);
onRenameTab?.(renamingTab, _tabname, oldName);
handleActiveChange(renamingTab, nwName);
}, [
handleActiveChange,
onRenameTab,
renamingTab,
tabname,
tabs,
validateTabname,
]);
handleActiveChange(renamingTab);
}, [handleActiveChange, onRenameTab, renamingTab, tabname, tabs, validateTabname]);
const handleCreateTab = useCallback(() => {
const res = validateTabname(tabname);
@@ -177,7 +170,7 @@ export const Tabs = ({
setTabnameError(`Error: ${res.error}`);
return;
}
const { result: _tabname = tabname } = res;
const { result: _tabname = tabname } = res
setIsNewtabDialogOpen(false);
setTabname("");
@@ -185,22 +178,17 @@ export const Tabs = ({
onCreateNewTab?.(_tabname);
handleActiveChange(tabs.length, _tabname);
}, [
validateTabname,
tabname,
onCreateNewTab,
handleActiveChange,
tabs.length,
]);
}, [validateTabname, tabname, onCreateNewTab, handleActiveChange, tabs.length]);
const handleCloseTab = useCallback(
(idx: number) => {
if (idx <= active && active !== 0) {
setActive(active - 1);
}
onCloseTab?.(idx, tabs[idx].header);
if (idx <= active && active !== 0) {
const nwActive = active - 1
handleActiveChange(nwActive, tabs[nwActive].header);
}
handleActiveChange(idx, tabs[idx].header);
},
[active, handleActiveChange, onCloseTab, tabs]
);
@@ -212,16 +200,13 @@ export const Tabs = ({
key: "close",
onSelect: () => handleCloseTab(idx),
};
const renameOption = (idx: number, tab: TabProps): Nullable<ContentMenuOption> => {
return (
onRenameTab && !tab.renameDisabled && {
type: "text",
label: "Rename",
key: "rename",
onSelect: () => setRenamingTab(idx),
}
);
}
const renameOption = (idx: number): Nullable<ContentMenuOption> =>
onRenameTab && {
type: "text",
label: "Rename",
key: "rename",
onSelect: () => setRenamingTab(idx),
};
return (
<>
@@ -240,7 +225,7 @@ export const Tabs = ({
<ContextMenu
key={tab.header}
options={
[closeOption(idx), renameOption(idx, tab)].filter(
[closeOption(idx), renameOption(idx)].filter(
Boolean
) as ContentMenuOption[]
}

View File

@@ -36,7 +36,7 @@
"lodash.xor": "^4.5.0",
"monaco-editor": "^0.33.0",
"next": "^12.0.4",
"next-auth": "^4.10.3",
"next-auth": "^4.10.1",
"next-plausible": "^3.2.0",
"next-themes": "^0.1.1",
"normalize-url": "^7.0.2",
@@ -80,4 +80,4 @@
"resolutions": {
"ripple-binary-codec": "=1.4.2"
}
}
}

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;
});
};

View File

@@ -2953,10 +2953,10 @@ natural-compare@^1.4.0:
resolved "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz"
integrity sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=
next-auth@^4.10.3:
version "4.10.3"
resolved "https://registry.yarnpkg.com/next-auth/-/next-auth-4.10.3.tgz#0a952dd5004fd2ac2ba414c990922cf9b33951a3"
integrity sha512-7zc4aXYc/EEln7Pkcsn21V1IevaTZsMLJwapfbnKA4+JY0+jFzWbt5p/ljugesGIrN4VOZhpZIw50EaFZyghJQ==
next-auth@^4.10.1:
version "4.10.1"
resolved "https://registry.yarnpkg.com/next-auth/-/next-auth-4.10.1.tgz#33b29265d12287bb2f6d267c8d415a407c27f0e9"
integrity sha512-F00vtwBdyMIIJ8IORHOAOHjVGTDEhhm9+HpB2BQ8r40WtGxqToWWLN7Z+2ZW/z2RFlo3zhcuAtUCPUzVJxtZwQ==
dependencies:
"@babel/runtime" "^7.16.3"
"@panva/hkdf" "^1.0.1"