Browse Source

Merge pull request #471 from LedgerHQ/fix-inputs

Fix inputs
master
Meriadec Pillet 7 years ago
committed by GitHub
parent
commit
0188bd7fc5
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 27
      src/components/modals/Send/01-step-amount.js
  2. 11
      src/components/modals/Send/AmountField.js
  3. 27
      src/components/modals/Send/RecipientField.js

27
src/components/modals/Send/01-step-amount.js

@ -33,6 +33,33 @@ function StepAmount({
<Box flow={4}> <Box flow={4}>
<AccountField t={t} onChange={onChangeAccount} value={account} /> <AccountField t={t} onChange={onChangeAccount} value={account} />
{/* HACK HACK HACK WTF */}
<div hidden>
{account &&
bridge &&
transaction && (
<RecipientField
account={account}
bridge={bridge}
transaction={transaction}
onChangeTransaction={onChangeTransaction}
t={t}
/>
)}
{account &&
bridge &&
transaction && (
<AmountField
account={account}
bridge={bridge}
transaction={transaction}
onChangeTransaction={onChangeTransaction}
t={t}
/>
)}
</div>
{/* HACK HACK HACK WTF */}
{account && bridge && transaction ? ( {account && bridge && transaction ? (
<Fragment key={account.id}> <Fragment key={account.id}>
<RecipientField <RecipientField

11
src/components/modals/Send/AmountField.js

@ -30,8 +30,13 @@ class AmountField extends Component<*, { canBeSpent: boolean }> {
this.setState({ canBeSpent }) this.setState({ canBeSpent })
} }
onChange = (amount: number) => {
const { bridge, account, transaction, onChangeTransaction } = this.props
onChangeTransaction(bridge.editTransactionAmount(account, transaction, amount))
}
render() { render() {
const { bridge, account, transaction, onChangeTransaction, t } = this.props const { bridge, account, transaction, t } = this.props
const { canBeSpent } = this.state const { canBeSpent } = this.state
return ( return (
<Box flow={1}> <Box flow={1}>
@ -40,9 +45,7 @@ class AmountField extends Component<*, { canBeSpent: boolean }> {
withMax={false} withMax={false}
account={account} account={account}
canBeSpent={canBeSpent} canBeSpent={canBeSpent}
onChange={amount => onChange={this.onChange}
onChangeTransaction(bridge.editTransactionAmount(account, transaction, amount))
}
value={bridge.getTransactionAmount(account, transaction)} value={bridge.getTransactionAmount(account, transaction)}
/> />
</Box> </Box>

27
src/components/modals/Send/RecipientField.js

@ -45,8 +45,21 @@ class RecipientField<Transaction> extends Component<Props<Transaction>, { isVali
this.setState({ isValid }) this.setState({ isValid })
} }
onChange = (recipient: string, maybeExtra: ?Object) => {
const { bridge, account, transaction, onChangeTransaction } = this.props
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
}
render() { render() {
const { bridge, account, transaction, onChangeTransaction, t } = this.props const { bridge, account, transaction, t } = this.props
const { isValid } = this.state const { isValid } = this.state
const value = bridge.getTransactionRecipient(account, transaction) const value = bridge.getTransactionRecipient(account, transaction)
return ( return (
@ -59,17 +72,7 @@ class RecipientField<Transaction> extends Component<Props<Transaction>, { isVali
withQrCode withQrCode
error={!value || isValid ? null : `This is not a valid ${account.currency.name} address`} error={!value || isValid ? null : `This is not a valid ${account.currency.name} address`}
value={value} value={value}
onChange={(recipient, maybeExtra) => { onChange={this.onChange}
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> </Box>
) )

Loading…
Cancel
Save