From f33120ac1ec5aae017a2bb89ad4d08cfc77de255 Mon Sep 17 00:00:00 2001 From: David Nicholson Date: Thu, 5 Nov 2020 15:20:38 -0800 Subject: [PATCH] factor out autocomplete data --- .../invokeFilePanelController.ts | 16 ++++++++++------ src/panel/views/InvokeFile.tsx | 18 ++++++++++-------- src/shared/autoCompleteData.ts | 9 +++++++++ src/shared/viewState/invokeFileViewState.ts | 6 ++---- 4 files changed, 31 insertions(+), 18 deletions(-) create mode 100644 src/shared/autoCompleteData.ts diff --git a/src/extension/panelControllers/invokeFilePanelController.ts b/src/extension/panelControllers/invokeFilePanelController.ts index fe7a58f..048eb99 100644 --- a/src/extension/panelControllers/invokeFilePanelController.ts +++ b/src/extension/panelControllers/invokeFilePanelController.ts @@ -33,9 +33,11 @@ export default class InvokeFilePanelController extends PanelControllerBase< view: "invokeFile", panelTitle: "Invoke File Editor", fileContents: [], - contracts: {}, - nefHints: {}, - addressSuggestions: [], + autoCompleteData: { + contracts: {}, + nefHints: {}, + addressSuggestions: [], + }, errorText: "", connectedTo: "", connectionState: "none", @@ -214,9 +216,11 @@ export default class InvokeFilePanelController extends PanelControllerBase< this.updateViewState({ connectedTo: this.activeConnection.connection?.blockchainIdentifier.name, connectionState, - contracts, - nefHints, - addressSuggestions, + autoCompleteData: { + contracts, + nefHints, + addressSuggestions, + }, }); } diff --git a/src/panel/views/InvokeFile.tsx b/src/panel/views/InvokeFile.tsx index 17dbe63..56086d9 100644 --- a/src/panel/views/InvokeFile.tsx +++ b/src/panel/views/InvokeFile.tsx @@ -33,12 +33,14 @@ export default function InvokeFile({ viewState, postMessage }: Props) { }} > - {viewState.addressSuggestions.map((_) => ( + {viewState.autoCompleteData.addressSuggestions.map((_) => (
postMessage({ @@ -67,8 +69,8 @@ export default function InvokeFile({ viewState, postMessage }: Props) { ))} postMessage({ diff --git a/src/shared/autoCompleteData.ts b/src/shared/autoCompleteData.ts new file mode 100644 index 0000000..cd45934 --- /dev/null +++ b/src/shared/autoCompleteData.ts @@ -0,0 +1,9 @@ +import { ContractManifestJson } from "@cityofzion/neon-core/lib/sc"; + +type AutoCompleteData = { + contracts: { [hashOrNefFile: string]: ContractManifestJson }; + nefHints: { [hash: string]: { [nefPath: string]: boolean } }; + addressSuggestions: string[]; +}; + +export default AutoCompleteData; diff --git a/src/shared/viewState/invokeFileViewState.ts b/src/shared/viewState/invokeFileViewState.ts index d434386..0a20466 100644 --- a/src/shared/viewState/invokeFileViewState.ts +++ b/src/shared/viewState/invokeFileViewState.ts @@ -1,4 +1,4 @@ -import { ContractManifestJson } from "@cityofzion/neon-core/lib/sc"; +import AutoCompleteData from "../autocompleteData"; type InvokeFileViewState = { view: "invokeFile"; @@ -8,9 +8,7 @@ type InvokeFileViewState = { operation?: string; args?: (string | number)[]; }[]; - contracts: { [hashOrNefFile: string]: ContractManifestJson }; - nefHints: { [hash: string]: { [nefPath: string]: boolean } }; - addressSuggestions: string[]; + autoCompleteData: AutoCompleteData; errorText: string; connectedTo: string; connectionState: "ok" | "connecting" | "none";