Skip to content

Commit

Permalink
add accounts panel
Browse files Browse the repository at this point in the history
  • Loading branch information
spoo-bar committed Jun 21, 2024
1 parent 621c247 commit efa61b1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 6 deletions.
13 changes: 13 additions & 0 deletions media/wasm-vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ function main() {
{ title: 'Address', columnDataKey: 'Header4' },
];

document.getElementById('accounts-grid').rowsData = [{}];
document.getElementById('accounts-grid').columnDefinitions = [
{ title: '#', columnDataKey: 'Header1' },
{ title: 'Address', columnDataKey: 'Header2' },
{ title: 'Mnemonic', columnDataKey: 'Header3' },
{ title: 'Balance', columnDataKey: 'Header4' },
];

// Handle the message inside the webview
window.addEventListener('message', event => {
const message = event.data; // The JSON data the extension sent
Expand All @@ -64,6 +72,11 @@ function main() {
break;
}
});

for(const acc of accountsData){
const length = document.getElementById('accounts-grid').rowsData.length;
document.getElementById('accounts-grid').rowsData.push({ Header1: length, Header2: acc.address, Header3: acc.mnemonic, Header4: acc.balance});
}
}

function displayResponseDataGrid() {
Expand Down
40 changes: 34 additions & 6 deletions src/views/wasmVmPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,25 @@ import * as vscode from "vscode";
import { CWSimulateApp } from '@terran-one/cw-simulate';
import { Coin, parseCoins } from "@cosmjs/launchpad";
import { ChainConfig } from "../helpers/workspace";
import { WrapWallet } from "../helpers/sign/wrapwallet";


export class WasmVmPanel {
public static currentPanel: WasmVmPanel | undefined;
private accounts = [];
private readonly _panel: vscode.WebviewPanel;
private _disposables: vscode.Disposable[] = [];

private readonly _wasmBinary: Uint8Array;
private readonly _app: CWSimulateApp;
private readonly _codeId: number;

private readonly mnemonics = [
"future master you three together square ski wrong shoulder online ridge tattoo",
"vacant tenant leave hill unique bless song manual model junk because slot",
"flock grape accident crowd helmet rifle giraffe marine toilet zebra attitude wrestle"
]

constructor(panel: vscode.WebviewPanel, wasm: Uint8Array, chainConfig: ChainConfig) {
this._panel = panel;
this._wasmBinary = wasm;
Expand All @@ -21,12 +29,25 @@ export class WasmVmPanel {
bech32Prefix: chainConfig.addressPrefix,
});
this._codeId = this._app.wasm.create('', this._wasmBinary);

this._setWebviewMessageListener(this._panel.webview);
this._panel.onDidDispose(() => this.dispose(), null, this._disposables);
}

public async getWebviewContent(extensionUri: vscode.Uri) {
for(const mnemonic of this.mnemonics) {
const wallet = await WrapWallet.fromMnemonic(global.workspaceChain.signType, global.workspaceChain.coinType, mnemonic, {
prefix: global.workspaceChain.addressPrefix
});
const addr = (await wallet.getAccounts())[0].address;
const balance = 1000000 + global.workspaceChain.chainDenom;
this._app.bank.setBalance(addr, parseCoins(balance));
this.accounts.push({
address: addr,
balance: balance,
mnemonic: wallet.mnemonic,
});
}

const toolkitUri = this.getUri(this._panel.webview, extensionUri, [
"node_modules",
"@vscode",
Expand All @@ -43,6 +64,9 @@ export class WasmVmPanel {
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<script type="module" src="${toolkitUri}"></script>
<script>
var accountsData = ${JSON.stringify(this.accounts)};
</script>
<script type="module" src="${mainUri}"></script>
<title>${this._panel.title}</title>
</head>
Expand All @@ -53,13 +77,17 @@ export class WasmVmPanel {
<vscode-panels id="meta-panel" aria-label="Default">
<vscode-panel-tab id="tab-1">${vscode.l10n.t("SETUP")}</vscode-panel-tab>
<vscode-panel-tab id="tab-2">${vscode.l10n.t("CONTRACTS")}</vscode-panel-tab>
<vscode-panel-tab id="tab-3">${vscode.l10n.t("ACCOUNTS")}</vscode-panel-tab>
<vscode-panel-view id="view-1">
<vscode-text-field disabled value="${this._app.chainId}" style="margin-right:20px;">${vscode.l10n.t("Chain ID")}</vscode-text-field>
<vscode-text-field disabled value="${this._app.bech32Prefix}" style="margin-right:20px;">${vscode.l10n.t("Bech32 Prefix")}</vscode-text-field>
<vscode-text-field disabled value="${this._app.height}" style="margin-right:20px;">${vscode.l10n.t("Block Height")}</vscode-text-field>
<vscode-text-field disabled value="${this._app.chainId}" style="margin-right:20px;">${vscode.l10n.t("Chain ID")}</vscode-text-field>
<vscode-text-field disabled value="${this._app.bech32Prefix}" style="margin-right:20px;">${vscode.l10n.t("Bech32 Prefix")}</vscode-text-field>
<vscode-text-field disabled value="${this._app.height}" style="margin-right:20px;">${vscode.l10n.t("Block Height")}</vscode-text-field>
</vscode-panel-view>
<vscode-panel-view id="view-2">
<vscode-data-grid id="contracts-grid" grid-template-columns="5% 20% 75%" aria-label="Default"></vscode-data-grid>
<vscode-data-grid id="contracts-grid" grid-template-columns="5% 20% 75%" aria-label="Default"></vscode-data-grid>
</vscode-panel-view>
<vscode-panel-view id="view-3">
<vscode-data-grid id="accounts-grid" grid-template-columns="5% 35% 45% 15%" aria-label="Default"></vscode-data-grid>
</vscode-panel-view>
</vscode-panels>
<br />
Expand Down Expand Up @@ -159,7 +187,7 @@ export class WasmVmPanel {


private async initializeContract(value: any) {
let funds : Coin[]
let funds: Coin[]
try {
funds = parseCoins(value.funds);
}
Expand Down

0 comments on commit efa61b1

Please sign in to comment.