on 13b09d9 help sign in
bridge/src/lib/error.js
38 lines 1.6 kB history raw
1const BRIDGE_ERROR = {
2 MISSING_WEB3: new Error('no web3 object found'),
3 MISSING_WALLET: new Error('no wallet found'),
4 MISSING_TXN: new Error('no transaction found'),
5 MISSING_CONTRACTS: new Error('no contracts found'),
6 MISSING_KEYSTORE: new Error('no keystore text found'),
7 MISSING_MNEMONIC: new Error('no authentication mnemonic found'),
8 MISSING_URBIT_WALLET: new Error('no urbit wallet found'),
9 MISSING_POINT: new Error('no point found'),
10 INVALID_ROUTE: new Error('invalid route'),
11 INVALID_NETWORK_TYPE: new Error('invalid network type'),
12 INVALID_WALLET_TYPE: new Error('invalid wallet type'),
13};
15const renderTxnError = (web3, msg) => {
16 const txnCost = (web3, msg) => {
17 const costWei = msg.match(/upfront cost is: ([0-9]+)/);
18 const costEth = web3.utils.fromWei(costWei[1], 'ether');
19 return parseFloat(costEth).toFixed(4);
20 };
22 const acctBalance = (web3, msg) => {
23 const balWei = msg.match(/sender's account only has: ([0-9]+)/);
24 const balEth = web3.utils.fromWei(balWei[1], 'ether');
25 return parseFloat(balEth).toFixed(4);
26 };
28 return msg.includes("doesn't have enough funds")
29 ? "The account doesn't have enough Ether. " +
30 `The up-front transaction cost is ${txnCost(web3, msg)} ETH, but the ` +
31 `account only holds ${acctBalance(web3, msg)} ETH.`
32 : 'You may want to verify that the account that has signed the ' +
33 'transaction holds sufficient Ether to pay for the gas, and ' +
34 "also that you haven't set the gas limit for the transaction " +
35 'too low.';
36};
38export { BRIDGE_ERROR, renderTxnError };