Skip to content

Commit

Permalink
Remove simulationResult and displayMessage params
Browse files Browse the repository at this point in the history
  • Loading branch information
vsakos committed Aug 30, 2023
1 parent cb61e41 commit b857c16
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 29 deletions.
2 changes: 1 addition & 1 deletion snap.manifest.json
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/solflare-wallet/aptos-snap.git"
},
"source": {
"shasum": "dvy77Sic8W9tPKgEL2q/nXlDWninPwmH8tAM8zqlg4k=",
"shasum": "w/3xBQyxmW5eRm+uZiYjuaTThHdHL/ldbqnog1p/s24=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
14 changes: 4 additions & 10 deletions src/index.js
Expand Up @@ -36,17 +36,14 @@ module.exports.onRpcRequest = async ({ origin, request }) => {
return pubkey;
}
case 'signTransaction': {
const { derivationPath, message, simulationResult = [], displayMessage = true } = request.params || {};
const { derivationPath, message } = request.params || {};

assertInput(derivationPath);
assertIsString(derivationPath);
assertInput(message);
assertIsString(message);
assertIsArray(simulationResult);
assertAllStrings(simulationResult);
assertIsBoolean(displayMessage);

const accepted = await renderSignTransaction(dappHost, message, simulationResult, displayMessage);
const accepted = await renderSignTransaction(dappHost, message);
assertConfirmation(accepted);

const keyPair = await deriveKeyPair(derivationPath);
Expand All @@ -59,19 +56,16 @@ module.exports.onRpcRequest = async ({ origin, request }) => {
};
}
case 'signAllTransactions': {
const { derivationPath, messages, simulationResults = [], displayMessage = true } = request.params || {};
const { derivationPath, messages } = request.params || {};

assertInput(derivationPath);
assertIsString(derivationPath);
assertInput(messages);
assertIsArray(messages);
assertInput(messages.length);
assertAllStrings(messages);
assertIsArray(simulationResults);
assertInput(messages.length === simulationResults.length);
assertIsBoolean(displayMessage);

const accepted = await renderSignAllTransactions(dappHost, messages, simulationResults, displayMessage);
const accepted = await renderSignAllTransactions(dappHost, messages);
assertConfirmation(accepted);

const keyPair = await deriveKeyPair(derivationPath);
Expand Down
24 changes: 6 additions & 18 deletions src/ui.js
@@ -1,5 +1,4 @@
import { panel, heading, text, copyable, divider } from '@metamask/snaps-ui';
import { assertAllStrings, assertInput, assertIsArray } from './utils';

export function renderGetPublicKey(host, pubkey) {
return snap.request({
Expand All @@ -16,43 +15,32 @@ export function renderGetPublicKey(host, pubkey) {
});
}

export function renderSignTransaction(host, message, simulationResult, displayMessage = true) {
const simulationResultItems = simulationResult.map((item) => text(item));

export function renderSignTransaction(host, message) {
return snap.request({
method: 'snap_dialog',
params: {
type: 'confirmation',
content: panel([
heading('Sign transaction'),
text(host),
...(simulationResultItems.length > 0 || displayMessage ? [divider()] : []),
...simulationResultItems,
...(displayMessage ? [copyable(message)] : [])
divider(),
copyable(message)
])
}
});
}

export function renderSignAllTransactions(host, messages, simulationResults, displayMessage = true) {
export function renderSignAllTransactions(host, messages) {
if (messages.length === 1) {
return renderSignTransaction(host, messages[0], simulationResults[0], displayMessage);
return renderSignTransaction(host, messages[0]);
}

const uiElements = [];

for (let i = 0; i < messages.length; i++) {
uiElements.push(divider());
uiElements.push(text(`Transaction ${i + 1}`));

assertIsArray(simulationResults[i]);
assertInput(simulationResults[i].length);
assertAllStrings(simulationResults[i]);

simulationResults[i].forEach((item) => uiElements.push(text(item)));
if (displayMessage) {
uiElements.push(copyable(messages[i]));
}
uiElements.push(copyable(messages[i]));
}

return snap.request({
Expand Down

0 comments on commit b857c16

Please sign in to comment.