Skip to content

Commit

Permalink
Merge pull request #78 from casper-ecosystem/feature/support-for-diff…
Browse files Browse the repository at this point in the history
…erent-deploys

Signer v1.1.1 - Support for different deploy types
  • Loading branch information
hoffmannjan authored Jun 3, 2021
2 parents 0f994b7 + 00e3961 commit 5889db6
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "casperlabs-signer",
"version": "1.1.0",
"version": "1.1.1",
"private": true,
"dependencies": {
"@babel/core": "^7.14.3",
Expand Down
2 changes: 1 addition & 1 deletion public/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"manifest_version": 2,
"version": "1.1.0",
"version": "1.1.1",
"name": "CasperLabs Signer",
"author": "https://casperlabs.io",
"description": "CasperLabs Signer tool for signing transactions on the blockchain.",
Expand Down
53 changes: 42 additions & 11 deletions src/background/SignMessageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as events from 'events';
import { AppState } from '../lib/MemStore';
import PopupManager from '../background/PopupManager';
import { DeployUtil, encodeBase16 } from 'casper-client-sdk';
import { toJS } from 'mobx';

export type deployStatus = 'unsigned' | 'signed' | 'failed';
export interface deployWithID {
Expand All @@ -25,6 +26,8 @@ export interface DeployData {
id?: any;
amount?: any;
target?: string;
validator?: string;
delegator?: string;
}

/**
Expand Down Expand Up @@ -259,16 +262,46 @@ export default class SignMessageManager extends events.EventEmitter {
let header = deploy.deploy.header;

// TODO: Double-check that this is correct way to determine deploy type.
let type = deploy.deploy.isTransfer()
const type = deploy.deploy.isTransfer()
? 'Transfer'
: deploy.deploy.session.isModuleBytes()
? 'Contract Call'
: 'Contract Deployment';

const amount = deploy.deploy.session.transfer
?.getArgByName('amount')!
.asBigNumber()
.toString();
let amount;
let target;
let validator;
let delegator;

if (deploy.deploy.session.transfer) {
amount = deploy.deploy.session.transfer
?.getArgByName('amount')!
.asBigNumber()
.toString();

target = encodeBase16(
deploy.deploy.session.transfer
?.getArgByName('target')!
.asBytesArray()!
);
}

if (deploy.deploy.session.storedContractByHash) {
amount = deploy.deploy.session.storedContractByHash
?.getArgByName('amount')!
.asBigNumber()
.toString();

validator = deploy.deploy.session.storedContractByHash
?.getArgByName('validator')!
.asPublicKey()
.toAccountHex();

delegator = deploy.deploy.session.storedContractByHash
?.getArgByName('delegator')!
.asPublicKey()
.toAccountHex();
}

const transferId = deploy.deploy.session.transfer
?.getArgByName('id')!
Expand All @@ -277,10 +310,6 @@ export default class SignMessageManager extends events.EventEmitter {
.asBigNumber()
.toString();

let target = encodeBase16(
deploy.deploy.session.transfer?.getArgByName('target')!.asBytesArray()!
);

return {
deployHash: encodeBase16(deploy.deploy.hash),
signingKey: deploy.signingKey,
Expand All @@ -291,8 +320,10 @@ export default class SignMessageManager extends events.EventEmitter {
payment: encodeBase16(deploy.deploy.payment.toBytes()),
deployType: type,
id: type === 'Transfer' ? transferId : undefined,
amount: type === 'Transfer' ? amount : undefined,
target: type === 'Transfer' ? target : undefined
amount: amount,
target: type === 'Transfer' ? target : undefined,
validator,
delegator
};
} else {
throw new Error('Deploy undefined!');
Expand Down
22 changes: 20 additions & 2 deletions src/popup/components/SignMessagePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import Grid from '@material-ui/core/Grid';
import Box from '@material-ui/core/Box';
import { deployWithID } from '../../background/SignMessageManager';

// TODO: Move it to helper functions
const numberWithSpaces = (num: number) =>
num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ' ');

interface Props extends RouteComponentProps {
signMessageContainer: SignMessageContainer;
authContainer: AccountManager;
Expand Down Expand Up @@ -78,17 +82,31 @@ class SignMessagePage extends React.Component<
this.createRow('Timestamp', deployData.timestamp),
this.createRow('Chain Name', deployData.chainName),
this.createRow('Gas Price', deployData.gasPrice),
this.createRow('Deploy Type', deployData.deployType)
this.createRow('Deploy Type', deployData.deployType),
this.createRow('Amount', `${numberWithSpaces(deployData.amount)} motes`)
];
if (deployData.deployType === 'Transfer') {
this.setState({
rows: [
...baseRows,
this.createRow('To', this.truncateString(deployData.target!, 6, 6)),
this.createRow('Amount', deployData.amount),
this.createRow('Transfer ID', deployData.id)
]
});
} else if (deployData.deployType === 'Contract Deployment') {
this.setState({
rows: [
...baseRows,
this.createRow(
'Validator',
this.truncateString(deployData.validator!, 6, 6)
),
this.createRow(
'Delegator',
this.truncateString(deployData.delegator!, 6, 6)
)
]
});
} else {
this.setState({ rows: baseRows });
}
Expand Down

0 comments on commit 5889db6

Please sign in to comment.