+
+ {
+ if (!txStep) return;
+ if (args.rawInput === 'exit') {
+ terminalRef.current?.pushToStdout('Command cancelled');
+ setTxStep(null);
return;
}
- const [key, value] = args.rawInput.split('=');
- if (!key || !value) {
+ if (txStep === 'start') {
terminalRef.current?.pushToStdout(
- 'type data in key=value format',
+ 'Complete all the following steps to create a command',
);
}
- let val;
- try {
- val = JSON.parse(value);
- } catch (e) {
- val = value;
+ if (txStep === 'start') {
+ setTxStep('code');
+ return;
}
- setCommandParts(
- (prev) =>
- prev && {
- ...prev,
- data: { ...prev.data, [key]: val },
- },
- );
- }
- if (txStep === 'signer' && args.rawInput) {
- setCommandParts(
- (prev) =>
- prev && {
- ...prev,
- signer: [
- ...prev.signer,
- { publicKey: args.rawInput, clist: [] },
- ],
- },
- );
- setTxStep('capability');
- return;
- }
- if (txStep === 'capability') {
- if (!args.rawInput) {
- setTxStep('signer');
+ if (txStep === 'code') {
+ setCommandParts({ code: args.rawInput, data: {}, signer: [] });
+ setTxStep('data');
return;
}
- const sections = execCodeParser(args.rawInput);
- const clist = sections?.map(
- (section) =>
- ({
- name: `${getSection(section.function.namespace)}${getSection(section.function.module)}${section.function.name}`,
- args: section.args.map(createCapArgs),
- }) as ICap,
- );
- if (clist) {
- const lastSigner = commandParts?.signer.at(-1);
- lastSigner?.clist.push(...clist);
- setCommandParts((prev) => ({ ...prev }) as ICommandParts);
+ if (txStep === 'data') {
+ if (!args.rawInput) {
+ setTxStep('signer');
+ return;
+ }
+ const [key, value] = args.rawInput.split('=');
+ if (!key || !value) {
+ terminalRef.current?.pushToStdout(
+ 'type data in key=value format',
+ );
+ }
+ let val;
+ try {
+ val = JSON.parse(value);
+ } catch (e) {
+ val = value;
+ }
+ setCommandParts(
+ (prev) =>
+ prev && {
+ ...prev,
+ data: { ...prev.data, [key]: val },
+ },
+ );
}
- }
- if (txStep === 'signer' && !args.rawInput) {
- const cmd = getCommand(
- commandParts!,
- getPublicKeyData,
- ) as IPartialPactCommand;
- setCommand(cmd);
- terminalRef.current?.pushToStdout(JSON.stringify(cmd, null, 2));
- setTxStep(null);
- return;
- }
- // if (args.result || args.command === 'clear') return;
- // // return args.join(' ');
- }}
- />
-
-
+ if (txStep === 'signer' && args.rawInput) {
+ setCommandParts(
+ (prev) =>
+ prev && {
+ ...prev,
+ signer: [
+ ...prev.signer,
+ { publicKey: args.rawInput, clist: [] },
+ ],
+ },
+ );
+ setTxStep('capability');
+ return;
+ }
+ if (txStep === 'capability') {
+ if (!args.rawInput) {
+ setTxStep('signer');
+ return;
+ }
+ const sections = execCodeParser(args.rawInput);
+ const clist = sections?.map(
+ (section) =>
+ ({
+ name: `${getSection(section.function.namespace)}${getSection(section.function.module)}${section.function.name}`,
+ args: section.args.map(createCapArgs),
+ }) as ICap,
+ );
+ if (clist) {
+ const lastSigner = commandParts?.signer.at(-1);
+ lastSigner?.clist.push(...clist);
+ setCommandParts((prev) => ({ ...prev }) as ICommandParts);
+ }
+ }
+ if (txStep === 'signer' && !args.rawInput) {
+ const cmd = getCommand(
+ commandParts!,
+ getPublicKeyData,
+ ) as IPartialPactCommand;
+ setCommand(cmd);
+ terminalRef.current?.pushToStdout(JSON.stringify(cmd, null, 2));
+ setTxStep(null);
+ return;
+ }
+ // if (args.result || args.command === 'clear') return;
+ // // return args.join(' ');
+ }}
+ />
+