Skip to content

Commit

Permalink
Merge pull request #16 from Weminal-labs/feature/ui
Browse files Browse the repository at this point in the history
feat: update UI, MoveCall & add Build, Test, Faucet
  • Loading branch information
tung-lee authored Apr 10, 2024
2 parents 81efd26 + 884653e commit 4f8ee97
Show file tree
Hide file tree
Showing 31 changed files with 888 additions and 664 deletions.
7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,3 @@ Open Sui-simulator extension: You can open by Command Palette if you're using on
* Add address and gas: You can create new address by import an existing seed phrase or generate new one
* Build, test and Publish: publish your package ID on the Sui network.
* Package Explorer: Developers can examine modules, functions, and make calls to them

--
## Following extension guidelines

Ensure that you've read through the extensions guidelines and follow the best practices for creating your extension.

* [Extension Guidelines](https://code.visualstudio.com/api/references/extension-guidelines)
Binary file added media/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions media/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion media/tools.svg

This file was deleted.

10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{
"name": "sui-simulator-vscode",
"displayName": "sui-simulator-vscode",
"displayName": "sui-simulator",
"icon": "media/icon.png",
"publisher": "weminal-labs",
"description": "",
"version": "0.3.0",
"version": "0.4.0",
"repository": "https://github.com/Weminal-labs/sui-simulator-vscode",
"engines": {
"vscode": "^1.87.0"
Expand All @@ -18,7 +20,7 @@
{
"id": "sui-simulator-sidebar-view",
"title": "Sui Simulator",
"icon": "media/tools.svg"
"icon": "media/logo.svg"
}
]
},
Expand All @@ -28,7 +30,7 @@
"type": "webview",
"id": "sui-simulator-sidebar",
"name": "Sui Simulator",
"icon": "media/tools.svg",
"icon": "media/logo.svg",
"contextualTitle": "Sui Simulator"
}
]
Expand Down
7 changes: 6 additions & 1 deletion src/enums/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export enum MoveCallStatus {
BEGIN,
NORMAL,
FINISH,
ERROR,
};
Expand All @@ -17,6 +17,7 @@ export enum MoveCallActionType {
ADD_ARG = "ADD_ARG",
SET_VALUE_TO_ARG = "SET_VALUE_TO_ARG",
SET_RESPONSE = "SET_RESPONSE",
SET_STATUS_NORMAL = "SET_STATUS_NORMAL",
};

export enum SuiCommand {
Expand All @@ -26,4 +27,8 @@ export enum SuiCommand {
SWITCH_NETWORK = "SWITCH_NETWORK",
GET_NETWORKS = "GET_NETWORKS",
PUBLISH_PACKAGE = "PUBLISH_PACKAGE",
CALL_FUNCTION = "CALL_FUNCTION",
REQUEST_FAUCET = "REQUEST_FAUCET",
BUILD_PACKAGE = "BUILD_PACKAGE",
TEST_PACKAGE = "TEST_PACKAGE",
}
102 changes: 84 additions & 18 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Import the module and reference it with the alias vscode in your code below
import * as vscode from 'vscode';
import { MessageHandlerData } from '@estruyf/vscode';
import { build, publish } from './suiCommand';
import { SuiSimulatorTerminal } from './suiSimulatorTerminal';
import { WebviewProvider } from './WebviewProvider';
import { exec } from "child_process";
import { promisify } from "util";
Expand All @@ -11,10 +11,10 @@ import { SuiCommand } from './enums';
interface MyCustomTerminalResponse {
stdout: string;
stderr: {
message: string;
isError: boolean;
message: string;
isError: boolean;
};
}
}

// This method is called when your extension is activated
// Your extension is activated the very first time the command is executed
Expand Down Expand Up @@ -73,9 +73,18 @@ export function activate(context: vscode.ExtensionContext) {
}));
}

let suiSimulatorTerminal = new SuiSimulatorTerminal();
let suiPath = "sui";

export const handleReceivedMessage = async (message: any, webView: any, context: any) => {
const { command, requestId, payload } = message;
console.log(suiPath);

switch (command) {
case "CHANGE_SUI_PATH":
suiPath = payload.suiPath;
console.log(suiPath);
break;
case "SUI_TERMINAL":
let resp = {
stderr: "",
Expand All @@ -93,7 +102,7 @@ export const handleReceivedMessage = async (message: any, webView: any, context:
switch (payload.cmd) {
case SuiCommand.GET_ADDRESSES:

resp = await execNew("sui client addresses --json");
resp = await execNew(`${suiPath} client addresses --json`);

finalResp = {
stderr: {
Expand All @@ -105,7 +114,7 @@ export const handleReceivedMessage = async (message: any, webView: any, context:
break;
case SuiCommand.GET_GAS_OBJECTS:
try {
resp = await execNew("sui client gas --json");
resp = await execNew(`${suiPath} client gas --json`);

finalResp = {
stderr: {
Expand All @@ -120,7 +129,7 @@ export const handleReceivedMessage = async (message: any, webView: any, context:

break;
case SuiCommand.SWITCH_ADDRESS:
resp = await execNew(`sui client switch --address ${payload.address}`);
resp = await execNew(`${suiPath} client switch --address ${payload.address}`);

finalResp = {
stderr: {
Expand All @@ -131,7 +140,7 @@ export const handleReceivedMessage = async (message: any, webView: any, context:
};
break;
case SuiCommand.GET_NETWORKS:
resp = await execNew("sui client envs --json");
resp = await execNew(`${suiPath} client envs --json`);

finalResp = {
stderr: {
Expand All @@ -142,7 +151,7 @@ export const handleReceivedMessage = async (message: any, webView: any, context:
};
break;
case SuiCommand.SWITCH_NETWORK:
resp = await execNew(`sui client switch --env ${payload.network}`);
resp = await execNew(`${suiPath} client switch --env ${payload.network}`);

finalResp = {
stderr: {
Expand All @@ -154,7 +163,36 @@ export const handleReceivedMessage = async (message: any, webView: any, context:
break;
case SuiCommand.PUBLISH_PACKAGE:
try {
resp = await execNew(`/home/asus/Workspace/sui-testnet-v1.22.0/target/release/sui-ubuntu-x86_64 client publish --gas ${payload.gasObjectId} --gas-budget ${payload.gasBudget} ${vscode.workspace.workspaceFolders?.[0].uri.path} --json --skip-fetch-latest-git-deps --skip-dependency-verification`);
resp = await execNew(`${suiPath} client publish --gas ${payload.gasObjectId} --gas-budget ${payload.gasBudget} ${vscode.workspace.workspaceFolders?.[0].uri.path} --json --skip-fetch-latest-git-deps --skip-dependency-verification`);

finalResp = {
stderr: {
message: resp.stderr,
isError: false
},
stdout: resp.stdout
};

console.log("stderr:", finalResp.stderr);
console.log("stdout:", finalResp.stdout);
} catch (err: any) {
console.log(err.message);
finalResp = {
stderr: {
message: err.message,
isError: true
},
stdout: ""
};

}

break;

case SuiCommand.CALL_FUNCTION:
try {
resp = await execNew(`${suiPath} client call --package ${payload.packageId} --module ${payload.moduleName} --function ${payload.functionName} --json --gas-budget 10000000 ${payload.args.length > 0 ? "--args" : ""} ${payload.args?.join(" ")}
`);

finalResp = {
stderr: {
Expand All @@ -179,6 +217,42 @@ export const handleReceivedMessage = async (message: any, webView: any, context:
}

break;

case SuiCommand.REQUEST_FAUCET:
try {
resp = await execNew(`${suiPath} client faucet
`);

finalResp = {
stderr: {
message: resp.stderr,
isError: false
},
stdout: resp.stdout
};

console.log("stderr:", finalResp.stderr);
console.log("stdout:", finalResp.stdout);
} catch (err: any) {
console.log(err.message);
finalResp = {
stderr: {
message: err.message,
isError: true
},
stdout: ""
};

}
break;

case SuiCommand.BUILD_PACKAGE:
suiSimulatorTerminal.build(vscode.workspace.workspaceFolders?.[0].uri.path, suiPath);
break;

case SuiCommand.TEST_PACKAGE:
suiSimulatorTerminal.test(vscode.workspace.workspaceFolders?.[0].uri.path, suiPath);
break;
}

// Do something with the payload
Expand Down Expand Up @@ -208,14 +282,6 @@ export const handleReceivedMessage = async (message: any, webView: any, context:
// executeCommand(payload.command, payload.suiPath);
// break;

case "BUILD":
build(payload.packagePath, payload.suiPath);
break;

case "PUBLISH":
publish(payload.packagePath, payload.suiPath);
break;

case "SAVE_ALIASES":
context.workspaceState.update(payload.address, {
aliases: payload.aliases
Expand Down
29 changes: 0 additions & 29 deletions src/suiCommand.ts

This file was deleted.

35 changes: 35 additions & 0 deletions src/suiSimulatorTerminal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import * as vscode from 'vscode';

export class SuiSimulatorTerminal {
private terminal: vscode.Terminal;

constructor() {
this.terminal = vscode.window.createTerminal("Sui Simulator");
}

build(packagePath: string | undefined, suiPath: string) {
console.log(this.terminal.exitStatus);
if (this.isCloseTerminal()) {
this.createTerminal();
}
this.terminal.sendText(`${suiPath} move build -p ${packagePath}`);
this.terminal.show();
}

test(packagePath: string | undefined, suiPath: string) {
console.log(this.terminal.exitStatus);
if (this.isCloseTerminal()) {
this.createTerminal();
}
this.terminal.sendText(`${suiPath} move test -p ${packagePath}`);
this.terminal.show();
}

private createTerminal() {
this.terminal = vscode.window.createTerminal("Sui Simulator");
}

private isCloseTerminal(): boolean {
return this.terminal.exitStatus instanceof Object;
}
}
Loading

0 comments on commit 4f8ee97

Please sign in to comment.