From 548762b09a76cf973c8d86ccddc818d5390e519f Mon Sep 17 00:00:00 2001 From: Juan Cortes Ross Date: Sat, 25 Aug 2018 19:36:53 +0200 Subject: [PATCH] Auto tag from qrcode/pasting on ripple addresses --- src/bridge/RippleJSBridge.js | 28 ++++++++++++++--- src/components/AdvancedOptions/RippleKind.js | 33 +++++++++----------- 2 files changed, 38 insertions(+), 23 deletions(-) diff --git a/src/bridge/RippleJSBridge.js b/src/bridge/RippleJSBridge.js index f872eeb6..e718933a 100644 --- a/src/bridge/RippleJSBridge.js +++ b/src/bridge/RippleJSBridge.js @@ -463,10 +463,30 @@ const RippleJSBridge: WalletBridge = { getTransactionAmount: (a, t) => t.amount, - editTransactionRecipient: (account, t, recipient) => ({ - ...t, - recipient, - }), + editTransactionRecipient: (account, t, recipient) => { + const parts = recipient.split('?') + const params = new URLSearchParams(parts[1]) + recipient = parts[0] + + // Extract parameters we may need + for (const [key, value] of params.entries()) { + switch (key) { + case 'dt': + t.tag = parseInt(value, 10) || 0 + break + case 'amount': + t.amount = parseAPIValue(value || '0') + break + default: + // do nothing + } + } + + return { + ...t, + recipient, + } + }, EditFees, diff --git a/src/components/AdvancedOptions/RippleKind.js b/src/components/AdvancedOptions/RippleKind.js index b87cff5f..b77d528b 100644 --- a/src/components/AdvancedOptions/RippleKind.js +++ b/src/components/AdvancedOptions/RippleKind.js @@ -5,7 +5,6 @@ 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 = { tag: ?number, @@ -14,23 +13,19 @@ type Props = { } export default translate()(({ tag, onChangeTag, t }: Props) => ( - - - - - - - { - const tag = parseInt(str, 10) - if (!isNaN(tag) && isFinite(tag)) onChangeTag(tag) - else onChangeTag(undefined) - }} - /> - + + + + { + const tag = parseInt(str, 10) + if (!isNaN(tag) && isFinite(tag)) onChangeTag(tag) + else onChangeTag(undefined) + }} + /> - + ))