Skip to content

Commit

Permalink
factor out autocomplete data
Browse files Browse the repository at this point in the history
  • Loading branch information
djnicholson committed Nov 5, 2020
1 parent e9cef8a commit f33120a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 18 deletions.
16 changes: 10 additions & 6 deletions src/extension/panelControllers/invokeFilePanelController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
},
});
}

Expand Down
18 changes: 10 additions & 8 deletions src/panel/views/InvokeFile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ export default function InvokeFile({ viewState, postMessage }: Props) {
}}
>
<datalist id={argumentSuggestionListId}>
{viewState.addressSuggestions.map((_) => (
{viewState.autoCompleteData.addressSuggestions.map((_) => (
<option key={_} value={`@${_}`} />
))}
{Object.getOwnPropertyNames(viewState.contracts).map((_) => (
<option key={_} value={`#${_}`} />
))}
{Object.getOwnPropertyNames(viewState.autoCompleteData.contracts).map(
(_) => (
<option key={_} value={`#${_}`} />
)
)}
</datalist>
<div
style={{
Expand All @@ -55,8 +57,8 @@ export default function InvokeFile({ viewState, postMessage }: Props) {
contract={_.contract}
operation={_.operation}
args={_.args}
contracts={viewState.contracts}
nefHints={viewState.nefHints}
contracts={viewState.autoCompleteData.contracts}
nefHints={viewState.autoCompleteData.nefHints}
argumentSuggestionListId={argumentSuggestionListId}
onUpdate={(contract, operation, args) =>
postMessage({
Expand All @@ -67,8 +69,8 @@ export default function InvokeFile({ viewState, postMessage }: Props) {
))}
<InvocationStep
key={viewState.fileContents.length}
contracts={viewState.contracts}
nefHints={viewState.nefHints}
contracts={viewState.autoCompleteData.contracts}
nefHints={viewState.autoCompleteData.nefHints}
argumentSuggestionListId={argumentSuggestionListId}
onUpdate={(contract, operation, args) =>
postMessage({
Expand Down
9 changes: 9 additions & 0 deletions src/shared/autoCompleteData.ts
Original file line number Diff line number Diff line change
@@ -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;
6 changes: 2 additions & 4 deletions src/shared/viewState/invokeFileViewState.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ContractManifestJson } from "@cityofzion/neon-core/lib/sc";
import AutoCompleteData from "../autocompleteData";

type InvokeFileViewState = {
view: "invokeFile";
Expand All @@ -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";
Expand Down

0 comments on commit f33120a

Please sign in to comment.