@@ -1,5 +1,6 @@
1import Common, { Chain, Hardfork } from '@ethereumjs/common';
1import Common, { Chain, Hardfork } from '@ethereumjs/common';
2−import { Transaction } from '@ethereumjs/tx';
2+import { JsonTx, Transaction } from '@ethereumjs/tx';
3+import { ITxData } from '@walletconnect/types';
3import { toHex } from 'web3-utils';
4import { toHex } from 'web3-utils';
4import { safeFromWei, safeToWei } from './lib';
5import { safeFromWei, safeToWei } from './lib';
5import retry from 'async-retry';
6import retry from 'async-retry';
@@ -12,6 +13,7 @@ import { metamaskSignTransaction } from './metamask';
12import { addHexPrefix } from './utils/address';
13import { addHexPrefix } from './utils/address';
13import { CHECK_BLOCK_EVERY_MS, WALLET_TYPES } from './constants';
14import { CHECK_BLOCK_EVERY_MS, WALLET_TYPES } from './constants';
14import { patp2dec } from './patp2dec';
15import { patp2dec } from './patp2dec';
16+import Web3 from 'web3';
16const RETRY_OPTIONS = {
18const RETRY_OPTIONS = {
17 retries: 99999,
19 retries: 99999,
@@ -20,21 +22,31 @@ const RETRY_OPTIONS = {
20 randomize: false,
22 randomize: false,
25+// catch-all type: Metamask passes an obj shaped like ITxData, WC passes JsonTx + from
26+export type FakeSignableTx =
28+ | (JsonTx & { from: string; to: string; gas: string });
30+type TxSender = (txn: FakeSignableTx, web3: Web3) => Promise<string>; // Metamask requires Web3 (txhash)
23type SignedTx = {
32type SignedTx = {
24 serialize: () => string;
33 serialize: () => string;
27−//TODO merge with FakeSignResult, get it type-checking properly
28type FakeSignedTx = SignedTx & {
36type FakeSignedTx = SignedTx & {
29− txn: any;
37+ txn: FakeSignableTx;
30− send: (web3: any, txn: any) => Promise<string>; // txhash
38+ send: TxSender;
33−function FakeSignResult(txn, send) {
41+const FakeSignResult = (txn: FakeSignableTx, send: TxSender): FakeSignedTx => {
34− this.txn = txn;
43+ txn,
35− this.serialize = () => '???'; //NOTE update tank.js when changing this!
45+ return '???'; //NOTE update tank.js when changing this!
36− this.send = send;
47+ send,
39const signTransaction = async ({
51const signTransaction = async ({
@@ -142,19 +154,19 @@ const signTransaction = async ({
144const sendSignedTransaction = (
156const sendSignedTransaction = (
145− web3,
157+ web3: Web3,
146− stx: SignedTx,
158+ stx: Transaction | FakeSignedTx,
147 doubtNonceError: boolean
159 doubtNonceError: boolean
148): Promise<string> => {
160): Promise<string> => {
149 // if we couldn't sign it, we depend on the given sender function
161 // if we couldn't sign it, we depend on the given sender function
150− if (stx instanceof FakeSignResult) { //TODO set up for proper typecheck
162+ if (!(stx instanceof Transaction)) {
151 if (doubtNonceError) {
163 if (doubtNonceError) {
152 console.log('why doubting nonce error? tank unavailable without rawtx.');
164 console.log('why doubting nonce error? tank unavailable without rawtx.');
154 if (!stx.send) {
166 if (!stx.send) {
155 throw new Error('no sign+sending function available');
167 throw new Error('no sign+sending function available');
157− return stx.send(web3, stx.txn);
169+ return stx.send(stx.txn, web3);
160 let rawTx: string = hexify(stx.serialize());
172 let rawTx: string = hexify(stx.serialize());