Skip to content

Commit ffb1545

Browse files
committed
feat: update UX & sui command
1 parent ca5333e commit ffb1545

4 files changed

Lines changed: 58 additions & 24 deletions

File tree

src/extension.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import * as vscode from 'vscode';
44
import { join } from 'path';
55
import { MessageHandlerData } from '@estruyf/vscode';
6-
import { build, publish, test } from './suiCommand';
6+
import { build, publish, executeCommand } from './suiCommand';
77

88
// This method is called when your extension is activated
99
// Your extension is activated the very first time the command is executed
@@ -49,22 +49,30 @@ export function activate(context: vscode.ExtensionContext) {
4949
payload: `Hello from the extension!`
5050
} as MessageHandlerData<string>);
5151
break;
52-
52+
5353
case "GET_DATA_ERROR":
5454
panel.webview.postMessage({
5555
command,
5656
requestId, // The requestId is used to identify the response
5757
error: `Oops, something went wrong!`
5858
} as MessageHandlerData<string>);
5959
break;
60-
60+
6161
case "POST_DATA":
6262
vscode.window.showInformationMessage(`Received data from the webview: ${payload.data}`);
6363
test(payload.data);
6464
break;
6565

6666
case "SUI_TERMINAL":
67-
test(payload.command);
67+
executeCommand(payload.command);
68+
break;
69+
70+
case "BUILD":
71+
build(payload.path);
72+
break;
73+
74+
case "PUBLISH":
75+
publish(payload.path);
6876
break;
6977

7078
case "SAVE_ALIASES":
@@ -74,10 +82,10 @@ export function activate(context: vscode.ExtensionContext) {
7482
vscode.window.showInformationMessage("Aliases saved successfully!");
7583
});
7684

77-
// use value as undefined to remove the key
78-
// context.workspaceState.update("", undefined);
85+
// use value as undefined to remove the key
86+
// context.workspaceState.update("", undefined);
7987

80-
default:
88+
default:
8189
vscode.window.showInformationMessage(`Unknown command: ${command}`);
8290
}
8391
}, undefined, context.subscriptions);
@@ -97,7 +105,7 @@ export function deactivate() { }
97105

98106
const getWebviewContent = (context: vscode.ExtensionContext, webview: vscode.Webview) => {
99107
const jsFile = "webview.js";
100-
const localServerUrl = "http://localhost:9000";
108+
const localServerUrl = "http://localhost:9999";
101109

102110
let scriptUrl = null;
103111
let cssUrl = null;

src/suiCommand.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import * as vscode from 'vscode';
22

3-
export const build = () => {
3+
export const build = (path: string) => {
44
const terminal = vscode.window.createTerminal("Sui Simulator");
5-
terminal.sendText("sui move build");
5+
terminal.sendText(`sui move build -p ${path}`);
66
terminal.show();
77
};
88

9-
export const publish = () => {
9+
export const publish = (path: string) => {
1010
const terminal = vscode.window.createTerminal("Sui Simulator");
11-
terminal.sendText("sui client publish --gas-budget 10000000");
11+
terminal.sendText(`sui client publish --gas-budget 100000000 ${path}`);
1212
terminal.show();
1313
};
1414

15-
export const test = (command: string) => {
15+
export const executeCommand = (command: string) => {
1616
const terminal = vscode.window.createTerminal("Sui Simulator");
1717
terminal.sendText(command);
1818
terminal.show();

src/webview/App.tsx

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ export const App: React.FunctionComponent<IAppProps> = ({ }: React.PropsWithChil
2626
const [isError, setIsError] = useState<boolean>(false);
2727
const [response, setResponse] = useState<string>("");
2828

29+
const [buildPath, setBuildPath] = useState<string>("");
30+
const [publishPath, setPublishPath] = useState<string>("");
31+
2932
let keypair: Ed25519Keypair | null = null;
3033

3134
const handleNetworkChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
@@ -115,11 +118,11 @@ export const App: React.FunctionComponent<IAppProps> = ({ }: React.PropsWithChil
115118
useEffect(() => {
116119
getDetailPackage(suiClient, "0xcab68c8cd7e80f3dd06466da6b2c083d1fd50ab3e9be8e32395c19b53021c064").then((data) => {
117120
const modules = Object.keys(data as {});
118-
121+
119122
if (data) {
120123
for (const module of modules) {
121124
const { exposedFunctions } = data[module];
122-
console.log(exposedFunctions);
125+
123126
}
124127
}
125128
}).catch(err => console.log(err));
@@ -129,15 +132,40 @@ export const App: React.FunctionComponent<IAppProps> = ({ }: React.PropsWithChil
129132
<>
130133
<h1>Sui Simulator</h1>
131134
<hr />
135+
<h2>Network</h2>
132136
<select value={network} onChange={handleNetworkChange}>
133137
<option>devnet</option>
134138
<option>testnet</option>
135139
</select>
136140
<hr />
137-
<Input placeholder="Mnemonics" value={mnemonics} onChange={handleMnemonicsChange} />
138-
<Input placeholder="Package ID" value={packageId} onChange={(e) => setPackageId(e.target.value)} />
139-
<Input placeholder="Module" value={module} onChange={(e) => setModule(e.target.value)} />
140-
<Input placeholder="Function Name" value={functionName} onChange={(e) => setFunctionName(e.target.value)} />
141+
<h2>Buikd</h2>
142+
<Input placeholder="Path" value={buildPath} onChange={(e) => setBuildPath(e.target.value)} />
143+
<Button onClick={() => { sendMessage("BUILD", { path: buildPath }); }}>
144+
Build
145+
</Button>
146+
<h2>Publish</h2>
147+
<Input placeholder="Path" value={publishPath} onChange={(e) => setPublishPath(e.target.value)} />
148+
<Button onClick={() => { sendMessage("PUBLISH", { path: publishPath }); }}>
149+
Publish
150+
</Button>
151+
<hr />
152+
<h2>Call</h2>
153+
<div>
154+
<span>Mnemonics: </span>
155+
<Input placeholder="Mnemonics" value={mnemonics} onChange={handleMnemonicsChange} />
156+
</div>
157+
<div>
158+
<span>Package: </span>
159+
<Input placeholder="Package ID" value={packageId} onChange={(e) => setPackageId(e.target.value)} />
160+
</div>
161+
<div>
162+
<span>Module: </span>
163+
<Input placeholder="Module" value={module} onChange={(e) => setModule(e.target.value)} />
164+
</div>
165+
<div>
166+
<span>Function: </span>
167+
<Input placeholder="Function Name" value={functionName} onChange={(e) => setFunctionName(e.target.value)} />
168+
</div>
141169
<p>Args</p>
142170
{args.map((arg, index) => {
143171
return <> <input type="text" value={arg.value} onChange={(e) => {
@@ -163,11 +191,9 @@ export const App: React.FunctionComponent<IAppProps> = ({ }: React.PropsWithChil
163191
}}>
164192
Call
165193
</Button>
166-
<Button onClick={() => { sendMessage("SUI_TERMINAL", {command: "sui client objects"}); }}>
167-
Test Terminal
168-
</Button>
169194
{!isError ? <p>Result: {response}</p> : <p>Error: {error}</p>}
170-
<Aliases/>
195+
<hr />
196+
<Aliases />
171197
</>
172198
);
173199
};

webpack/webview.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const config = [
3838
plugins: [],
3939
devServer: {
4040
compress: true,
41-
port: 9000,
41+
port: 9999,
4242
hot: true,
4343
allowedHosts: "all",
4444
headers: {

0 commit comments

Comments
 (0)