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