Browse Source

Implement Gas limit advanced option & fix calculus estimation

master
Gaëtan Renaudeau 7 years ago
parent
commit
ac0a3c27d7
  1. 32
      src/bridge/EthereumJSBridge.js
  2. 36
      src/components/AdvancedOptions/EthereumKind.js
  3. 4
      src/helpers/signTransactionForCurrency/ethereum.js
  4. 1
      static/i18n/en/send.yml

32
src/bridge/EthereumJSBridge.js

@ -1,6 +1,7 @@
// @flow
import React from 'react'
import EthereumKind from 'components/FeesField/EthereumKind'
import FeesField from 'components/FeesField/EthereumKind'
import AdvancedOptions from 'components/AdvancedOptions/EthereumKind'
import throttle from 'lodash/throttle'
import flatMap from 'lodash/flatMap'
import uniqBy from 'lodash/uniqBy'
@ -14,10 +15,15 @@ import type { EditProps, WalletBridge } from './types'
// TODO in future it would be neat to support eip55
type Transaction = *
type Transaction = {
amount: number,
recipient: string,
gasPrice: number,
gasLimit: number,
}
const EditFees = ({ account, onChange, value }: EditProps<Transaction>) => (
<EthereumKind
<FeesField
onChange={gasPrice => {
onChange({ ...value, gasPrice })
}}
@ -26,6 +32,15 @@ const EditFees = ({ account, onChange, value }: EditProps<Transaction>) => (
/>
)
const EditAdvancedOptions = ({ onChange, value }: EditProps<Transaction>) => (
<AdvancedOptions
gasLimit={value.gasLimit}
onChange={gasLimit => {
onChange({ ...value, gasLimit })
}}
/>
)
// in case of a SELF send, 2 ops are returned.
const txToOps = (account: Account) => (tx: Tx): Operation[] => {
const freshAddress = account.freshAddress.toLowerCase()
@ -269,6 +284,7 @@ const EthereumBridge: WalletBridge<Transaction> = {
amount: 0,
recipient: '',
gasPrice: 0,
gasLimit: 0x5208,
}),
editTransactionAmount: (account, t, amount) => ({
@ -290,10 +306,12 @@ const EthereumBridge: WalletBridge<Transaction> = {
// $FlowFixMe
EditFees,
// FIXME gasPrice calc is wrong... need to multiply with gasLimit I guess ?
canBeSpent: (a, t) => Promise.resolve(t.amount + t.gasPrice <= a.balance),
getTotalSpent: (a, t) => Promise.resolve(t.amount + t.gasPrice),
getMaxAmount: (a, t) => Promise.resolve(a.balance - t.gasPrice),
// $FlowFixMe
EditAdvancedOptions,
canBeSpent: (a, t) => Promise.resolve(t.amount <= a.balance),
getTotalSpent: (a, t) => Promise.resolve(t.amount + t.gasPrice * t.gasLimit),
getMaxAmount: (a, t) => Promise.resolve(a.balance - t.gasPrice * t.gasLimit),
signAndBroadcast: async (a, t, deviceId) => {
const api = apiForCurrency(a.currency)

36
src/components/AdvancedOptions/EthereumKind.js

@ -0,0 +1,36 @@
// @flow
import React from 'react'
import { translate } from 'react-i18next'
import Box from 'components/base/Box'
import Input from 'components/base/Input'
import Label from 'components/base/Label'
import Spoiler from 'components/base/Spoiler'
type Props = {
gasLimit: number,
onChangeGasLimit: (?number) => void,
t: *,
}
export default translate()(({ gasLimit, onChangeGasLimit, t }: Props) => (
<Spoiler title="Advanced options">
<Box horizontal align="center" flow={5}>
<Box style={{ width: 200 }}>
<Label>
<span>{t('send:steps.amount.ethereumGasLimit')}</span>
</Label>
</Box>
<Box grow>
<Input
value={gasLimit}
onChange={str => {
const gasLimit = parseInt(str, 10)
if (!isNaN(gasLimit) && isFinite(gasLimit)) onChangeGasLimit(gasLimit)
else onChangeGasLimit(0x5208)
}}
/>
</Box>
</Box>
</Spoiler>
))

4
src/helpers/signTransactionForCurrency/ethereum.js

@ -27,6 +27,7 @@ export default async (
nonce: string,
recipient: string,
gasPrice: number,
gasLimit: number,
amount: number,
},
) => {
@ -34,11 +35,10 @@ export default async (
const chainId = getNetworkId(currencyId)
if (!chainId) throw new Error(`chainId not found for currency=${currencyId}`)
const gasLimit = '0x5208' // cost of a simple send
const tx = new EthereumTx({
nonce: t.nonce,
gasPrice: `0x${t.gasPrice.toString(16)}`,
gasLimit,
gasLimit: `0x${t.gasLimit.toString(16)}`,
to: t.recipient,
value: `0x${t.amount.toString(16)}`,
chainId,

1
static/i18n/en/send.yml

@ -12,6 +12,7 @@ steps:
useRBF: Use the RBF transaction
message: Leave a message (140)
rippleTag: Tag
ethereumGasLimit: Gas limit
connectDevice:
title: Connect device
verification:

Loading…
Cancel
Save