Skip to content
This repository has been archived by the owner on Jan 31, 2023. It is now read-only.

Commit

Permalink
bring back transaction webview for v2 (#2642)
Browse files Browse the repository at this point in the history
Signed-off-by: Erin Hughes <Erin.Hughes@ibm.com>
  • Loading branch information
erin-hughes committed Oct 2, 2020
1 parent ab882ea commit 0dc7b26
Show file tree
Hide file tree
Showing 19 changed files with 540 additions and 555 deletions.
18 changes: 5 additions & 13 deletions packages/blockchain-extension/extension/webview/TransactionView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
'use strict';
import * as vscode from 'vscode';
import { ReactView } from './ReactView';
import { ExtensionCommands } from '../../ExtensionCommands';

export class TransactionView extends ReactView {
protected appState: any;
Expand All @@ -27,25 +26,18 @@ export class TransactionView extends ReactView {

async openPanelInner(panel: vscode.WebviewPanel): Promise<void> {
panel.webview.onDidReceiveMessage(async (message: {command: string, data: any}) => {
if (message.command === 'submit') {
const response: string = await vscode.commands.executeCommand(ExtensionCommands.SUBMIT_TRANSACTION, undefined, undefined, undefined, message.data);
panel.webview.postMessage({
output: response
});
} else if (message.command === 'evaluate') {
const response: string = await vscode.commands.executeCommand(ExtensionCommands.EVALUATE_TRANSACTION, undefined, undefined, undefined, message.data);
panel.webview.postMessage({
output: response
});
}
const response: string = await vscode.commands.executeCommand(message.command, undefined, undefined, undefined, message.data);
panel.webview.postMessage({
transactionOutput: response
});
});
this.loadComponent(panel);
}

loadComponent(panel: vscode.WebviewPanel): void {
panel.webview.postMessage({
path: '/transaction',
state: this.appState
transactionData: this.appState
});
}
}
36 changes: 3 additions & 33 deletions packages/blockchain-extension/test/webview/TransactionView.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ describe('TransactionView', () => {
createWebviewPanelStub.should.have.been.called;
postMessageStub.should.have.been.calledWith({
path: '/transaction',
state: mockAppState
transactionData: mockAppState
});
});

Expand All @@ -137,7 +137,7 @@ describe('TransactionView', () => {
postMessage: mySandBox.stub(),
onDidReceiveMessage: async (callback: any): Promise<void> => {
await callback({
command: 'submit',
command: ExtensionCommands.SUBMIT_TRANSACTION,
data: transactionObject
});
resolve();
Expand Down Expand Up @@ -167,7 +167,7 @@ describe('TransactionView', () => {
postMessage: mySandBox.stub(),
onDidReceiveMessage: async (callback: any): Promise<void> => {
await callback({
command: 'evaluate',
command: ExtensionCommands.EVALUATE_TRANSACTION,
data: transactionObject
});
resolve();
Expand All @@ -188,34 +188,4 @@ describe('TransactionView', () => {
executeCommandStub.should.have.been.calledWith(ExtensionCommands.EVALUATE_TRANSACTION, undefined, undefined, undefined, transactionObject);
});

it('should not do anything if it receives an invalid message', async () => {
const onDidReceiveMessagePromises: any[] = [];

onDidReceiveMessagePromises.push(new Promise((resolve: any): void => {
createWebviewPanelStub.returns({
webview: {
postMessage: mySandBox.stub(),
onDidReceiveMessage: async (callback: any): Promise<void> => {
await callback({
command: 'invalid',
data: transactionObject
});
resolve();
}
},
reveal: (): void => {
return;
},
onDidDispose: mySandBox.stub(),
onDidChangeViewState: mySandBox.stub()
});
}));

const transactionView: TransactionView = new TransactionView(context, mockAppState);
await transactionView.openView(false);
await Promise.all(onDidReceiveMessagePromises);

executeCommandStub.should.not.have.been.called;
});

});
Loading

0 comments on commit 0dc7b26

Please sign in to comment.