Gaëtan Renaudeau
7 years ago
21 changed files with 266 additions and 113 deletions
@ -0,0 +1,14 @@ |
|||
// @flow
|
|||
import React from 'react' |
|||
import Box from 'components/base/Box' |
|||
import Label from 'components/base/Label' |
|||
import SelectAccount from 'components/SelectAccount' |
|||
|
|||
const AccountField = ({ onChange, value, t }: *) => ( |
|||
<Box flow={1}> |
|||
<Label>{t('send:steps.amount.selectAccountDebit')}</Label> |
|||
<SelectAccount onChange={onChange} value={value} /> |
|||
</Box> |
|||
) |
|||
|
|||
export default AccountField |
@ -0,0 +1,53 @@ |
|||
// @flow
|
|||
import React, { Component } from 'react' |
|||
import Box from 'components/base/Box' |
|||
import Label from 'components/base/Label' |
|||
import RequestAmount from 'components/RequestAmount' |
|||
|
|||
class AmountField extends Component<*, { canBeSpent: boolean }> { |
|||
state = { |
|||
canBeSpent: true, |
|||
} |
|||
componentDidMount() { |
|||
this.resync() |
|||
} |
|||
componentDidUpdate(nextProps: *) { |
|||
if ( |
|||
nextProps.account !== this.props.account || |
|||
nextProps.transaction !== this.props.transaction |
|||
) { |
|||
this.resync() |
|||
} |
|||
} |
|||
componentWillUnmount() { |
|||
this.unmount = true |
|||
} |
|||
unmount = false |
|||
async resync() { |
|||
const { account, bridge, transaction } = this.props |
|||
const canBeSpent = await bridge.canBeSpent(account, transaction) |
|||
if (this.unmount) return |
|||
this.setState({ canBeSpent }) |
|||
} |
|||
|
|||
render() { |
|||
const { bridge, account, transaction, onChangeTransaction, t } = this.props |
|||
const { canBeSpent } = this.state |
|||
return ( |
|||
<Box flow={1}> |
|||
<Label>{t('send:steps.amount.amount')}</Label> |
|||
<RequestAmount |
|||
withMax={false} |
|||
account={account} |
|||
canBeSpent={canBeSpent} |
|||
onChange={amount => |
|||
onChangeTransaction(bridge.editTransactionAmount(account, transaction, amount)) |
|||
} |
|||
value={bridge.getTransactionAmount(account, transaction)} |
|||
/> |
|||
</Box> |
|||
) |
|||
} |
|||
} |
|||
|
|||
export default AmountField |
@ -0,0 +1,79 @@ |
|||
// @flow
|
|||
import React, { Component } from 'react' |
|||
import type { Account } from '@ledgerhq/live-common/lib/types' |
|||
import type { T } from 'types/common' |
|||
import type { WalletBridge } from 'bridge/types' |
|||
import Box from 'components/base/Box' |
|||
import Label from 'components/base/Label' |
|||
import LabelInfoTooltip from 'components/base/LabelInfoTooltip' |
|||
import RecipientAddress from 'components/RecipientAddress' |
|||
|
|||
type Props<Transaction> = { |
|||
t: T, |
|||
account: Account, |
|||
bridge: WalletBridge<Transaction>, |
|||
transaction: Transaction, |
|||
onChangeTransaction: Transaction => void, |
|||
} |
|||
|
|||
class RecipientField<Transaction> extends Component<Props<Transaction>, { isValid: boolean }> { |
|||
state = { |
|||
isValid: true, |
|||
} |
|||
componentDidMount() { |
|||
this.resync() |
|||
} |
|||
componentDidUpdate(nextProps: Props<Transaction>) { |
|||
if ( |
|||
nextProps.account !== this.props.account || |
|||
nextProps.transaction !== this.props.transaction |
|||
) { |
|||
this.resync() |
|||
} |
|||
} |
|||
componentWillUnmount() { |
|||
this.unmount = true |
|||
} |
|||
unmount = false |
|||
async resync() { |
|||
const { account, bridge, transaction } = this.props |
|||
const isValid = await bridge.isRecipientValid( |
|||
account.currency, |
|||
bridge.getTransactionRecipient(account, transaction), |
|||
) |
|||
if (this.unmount) return |
|||
this.setState({ isValid }) |
|||
} |
|||
|
|||
render() { |
|||
const { bridge, account, transaction, onChangeTransaction, t } = this.props |
|||
const { isValid } = this.state |
|||
const value = bridge.getTransactionRecipient(account, transaction) |
|||
return ( |
|||
<Box flow={1}> |
|||
<Label> |
|||
<span>{t('send:steps.amount.recipientAddress')}</span> |
|||
<LabelInfoTooltip ml={1} text={t('send:steps.amount.recipientAddress')} /> |
|||
</Label> |
|||
<RecipientAddress |
|||
withQrCode |
|||
error={!value || isValid ? null : `This is not a valid ${account.currency.name} address`} |
|||
value={value} |
|||
onChange={(recipient, maybeExtra) => { |
|||
const { amount, currency } = maybeExtra || {} |
|||
if (currency && currency.scheme !== account.currency.scheme) return false |
|||
let t = transaction |
|||
if (amount) { |
|||
t = bridge.editTransactionAmount(account, t, amount) |
|||
} |
|||
t = bridge.editTransactionRecipient(account, t, recipient) |
|||
onChangeTransaction(t) |
|||
return true |
|||
}} |
|||
/> |
|||
</Box> |
|||
) |
|||
} |
|||
} |
|||
|
|||
export default RecipientField |
@ -0,0 +1,3 @@ |
|||
// @flow
|
|||
|
|||
export const formatError = (e: Error) => e.message |
Loading…
Reference in new issue