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