Browse Source

Handle source===destination on select recipient for xrp

gre-patch-1
Juan Cortes Ross 6 years ago
parent
commit
6c2ef1ce46
No known key found for this signature in database GPG Key ID: 34A99C03E9455EB8
  1. 19
      src/bridge/RippleJSBridge.js
  2. 4
      src/bridge/types.js
  3. 10
      src/components/modals/Send/fields/RecipientField.js

19
src/bridge/RippleJSBridge.js

@ -136,7 +136,11 @@ async function signAndBroadcast({ a, t, deviceId, isCancelled, onSigned, onOpera
}
}
function isRecipientValid(recipient) {
function isRecipientValid(recipient, source) {
if (source === recipient) {
return false
}
try {
bs58check.decode(recipient)
return true
@ -145,6 +149,13 @@ function isRecipientValid(recipient) {
}
}
function getRecipientWarning(recipient, source) {
if (source === recipient) {
return new Error('InvalidAddressBecauseDestinationIsAlsoSource')
}
return null
}
function mergeOps(existing: Operation[], newFetched: Operation[]) {
const ids = existing.map(o => o.id)
const all = existing.concat(newFetched.filter(o => !ids.includes(o.id)))
@ -505,8 +516,10 @@ const RippleJSBridge: WalletBridge<Transaction> = {
pullMoreOperations: () => Promise.resolve(a => a), // FIXME not implemented
isRecipientValid: (currency, recipient) => Promise.resolve(isRecipientValid(recipient)),
getRecipientWarning: () => Promise.resolve(null),
isRecipientValid: (currency, recipient, source) =>
Promise.resolve(isRecipientValid(recipient, source)),
getRecipientWarning: (currency, recipient, source) =>
Promise.resolve(getRecipientWarning(recipient, source)),
createTransaction: () => ({
amount: BigNumber(0),

4
src/bridge/types.js

@ -52,8 +52,8 @@ export interface WalletBridge<Transaction> {
// count is user's desired number of ops to pull (but implementation can decide to ignore it or not)
pullMoreOperations(initialAccount: Account, count: number): Promise<(Account) => Account>;
isRecipientValid(currency: Currency, recipient: string): Promise<boolean>;
getRecipientWarning(currency: Currency, recipient: string): Promise<?Error>;
isRecipientValid(currency: Currency, recipient: string, source?: string): Promise<boolean>;
getRecipientWarning(currency: Currency, recipient: string, source?: string): Promise<?Error>;
// Related to send funds:

10
src/components/modals/Send/fields/RecipientField.js

@ -53,8 +53,12 @@ class RecipientField<Transaction> extends Component<
const { account, bridge, transaction } = this.props
const syncId = ++this.syncId
const recipient = bridge.getTransactionRecipient(account, transaction)
const isValid = await bridge.isRecipientValid(account.currency, recipient)
const warning = await bridge.getRecipientWarning(account.currency, recipient)
const isValid = await bridge.isRecipientValid(account.currency, recipient, account.freshAddress)
const warning = await bridge.getRecipientWarning(
account.currency,
recipient,
account.freshAddress,
)
if (syncId !== this.syncId) return
if (this.isUnmounted) return
this.setState({ isValid, warning })
@ -97,7 +101,7 @@ class RecipientField<Transaction> extends Component<
const error =
!value || isValid
? QRCodeRefusedReason
: new InvalidAddress(null, { currencyName: account.currency.name })
: warning || new InvalidAddress(null, { currencyName: account.currency.name })
return (
<Box flow={1}>

Loading…
Cancel
Save