@@ -1,5 +1,6 @@
11import 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';
34import { toHex } from 'web3-utils';
45import { safeFromWei, safeToWei } from './lib';
56import retry from 'async-retry';
@@ -12,6 +13,7 @@ import { metamaskSignTransaction } from './metamask';
1213import { addHexPrefix } from './utils/address';
1314import { CHECK_BLOCK_EVERY_MS, WALLET_TYPES } from './constants';
1415import { patp2dec } from './patp2dec';
16+import Web3 from 'web3';
1517
1618const RETRY_OPTIONS = {
1719 retries: 99999,
@@ -20,21 +22,31 @@ const RETRY_OPTIONS = {
2022 randomize: false,
2123};
2224
25+// catch-all type: Metamask passes an obj shaped like ITxData, WC passes JsonTx + from
26+export type FakeSignableTx =
27+ | ITxData
28+ | (JsonTx & { from: string; to: string; gas: string });
29+
30+type TxSender = (txn: FakeSignableTx, web3: Web3) => Promise<string>; // Metamask requires Web3 (txhash)
31+
2332type SignedTx = {
2433 serialize: () => string;
2534};
2635
27−//TODO merge with FakeSignResult, get it type-checking properly
2836type FakeSignedTx = SignedTx & {
29− txn: any;
30− send: (web3: any, txn: any) => Promise<string>; // txhash
37+ txn: FakeSignableTx;
38+ send: TxSender;
3139};
3240
33−function FakeSignResult(txn, send) {
34− this.txn = txn;
35− this.serialize = () => '???'; //NOTE update tank.js when changing this!
36− this.send = send;
37−}
41+const FakeSignResult = (txn: FakeSignableTx, send: TxSender): FakeSignedTx => {
42+ return {
43+ txn,
44+ serialize: () => {
45+ return '???'; //NOTE update tank.js when changing this!
46+ },
47+ send,
48+ };
49+};
3850
3951const signTransaction = async ({
4052 wallet,
@@ -142,19 +154,19 @@ const signTransaction = async ({
142154};
143155
144156const sendSignedTransaction = (
145− web3,
146− stx: SignedTx,
157+ web3: Web3,
158+ stx: Transaction | FakeSignedTx,
147159 doubtNonceError: boolean
148160): Promise<string> => {
149161 // 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)) {
151163 if (doubtNonceError) {
152164 console.log('why doubting nonce error? tank unavailable without rawtx.');
153165 }
154166 if (!stx.send) {
155167 throw new Error('no sign+sending function available');
156168 }
157− return stx.send(web3, stx.txn);
169+ return stx.send(stx.txn, web3);
158170 }
159171
160172 let rawTx: string = hexify(stx.serialize());