on master help sign in
Don't use Maybes for signTransaction
commit1caf845aec77171cd02196c2e5b92b95fd9a6788 authorFang <git@fang.io> dateTue 16 Jul 2019, 18:01 (7 years ago) parentd6d11df
3 files changed+11−21
src/components/old/StatelessTransaction.js+7−1 src/lib/txn.js+2−17 src/views/Invite/InviteEmail.js+2−3
src/components/old/StatelessTransaction.js+7−1
@@ -494,7 +494,13 @@ class StatelessTransaction extends React.Component {
494494 prop-size={'lg wide'}
495495 prop-color={signerButtonColor}
496496 onClick={() =>
497− signTransaction({ ...this.props, ...this.state, setStx: this.setStx })
497+ signTransaction({
498+ ...this.props,
499+ ...this.state,
500+ setStx: this.setStx,
501+ wallet: this.props.wallet.value,
502+ txn: txn.value,
503+ })
498504 }>
499505 {'Sign Transaction'}
500506 </Button>
src/lib/txn.js+2−17
@@ -4,7 +4,6 @@ import Tx from 'ethereumjs-tx';
44import { toWei, fromWei, toHex } from 'web3-utils';
55import * as retry from 'async-retry';
66
7−import { BRIDGE_ERROR } from './error';
87import { NETWORK_TYPES } from './network';
98import { ledgerSignTransaction } from './ledger';
109import { trezorSignTransaction } from './trezor';
@@ -114,21 +113,7 @@ const signTransaction = async config => {
114113 ? Object.assign(txParams, eip155Params)
115114 : txParams;
116115
117− const wal = wallet.matchWith({
118− Just: w => w.value,
119− Nothing: () => {
120− throw BRIDGE_ERROR.MISSING_WALLET;
121− },
122− });
123−
124− const sec = wal.privateKey;
125−
126− const utx = txn.matchWith({
127− Just: tx => Object.assign(tx.value, signingParams),
128− Nothing: () => {
129− throw BRIDGE_ERROR.MISSING_TXN;
130− },
131− });
116+ const utx = Object.assign(txn, signingParams);
132117
133118 const stx = new Tx(utx);
134119
@@ -137,7 +122,7 @@ const signTransaction = async config => {
137122 } else if (walletType === WALLET_TYPES.TREZOR) {
138123 await trezorSignTransaction(stx, walletHdPath);
139124 } else {
140− stx.sign(sec);
125+ stx.sign(wallet.privateKey);
141126 }
142127
143128 setStx(Just(stx));
src/views/Invite/InviteEmail.js+2−3
@@ -1,6 +1,5 @@
11import React, { useCallback, useEffect, useMemo, useState } from 'react';
22import cn from 'classnames';
3−import { Just } from 'folktale/maybe';
43import * as azimuth from 'azimuth-js';
54import {
65 Grid,
@@ -247,12 +246,12 @@ export default function InviteEmail() {
247246 owner.keys.address
248247 );
249248 const signedTx = await signTransaction({
250− wallet,
249+ wallet: _wallet,
251250 walletType,
252251 walletHdPath,
253252 networkType,
254253 // TODO: ^ make a useTransactionSigner to encapsulate this logic
255− txn: Just(inviteTx),
254+ txn: inviteTx,
256255 gasPrice: GAS_PRICE_GWEI.toString(),
257256 gasLimit: GAS_LIMIT.toString(),
258257 nonce: nonce + i,