From 1a13573aa09b15d2d835a1403e9a82705170baae Mon Sep 17 00:00:00 2001 From: lenondupe Date: Mon, 18 Dec 2017 21:04:01 +0100 Subject: [PATCH 1/6] #48 warn of payments to exchanges without memo --- controllers/send-widget.controller.es6 | 20 +++++++++++++++++++- known_accounts.es6 | 15 +++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 known_accounts.es6 diff --git a/controllers/send-widget.controller.es6 b/controllers/send-widget.controller.es6 index 8476ce9..241171c 100644 --- a/controllers/send-widget.controller.es6 +++ b/controllers/send-widget.controller.es6 @@ -5,6 +5,7 @@ import {Alert, AlertGroup} from 'interstellar-ui-messages'; import {Account, Asset, Keypair, Memo, Operation, Transaction, TransactionBuilder, xdr} from 'stellar-sdk'; import {FederationServer} from 'stellar-sdk'; import BasicClientError from '../errors'; +import knownAccounts from '../known_accounts'; import StellarLedger from 'stellar-ledger-api'; @Widget('send', 'SendWidgetController', 'interstellar-basic-client/send-widget') @@ -123,12 +124,17 @@ export default class SendWidgetController { this.memoBlocked = true; } else { this.memoBlocked = false; - } + + if (this.destination in knownAccounts && knownAccounts[this.destination].memo_required) { + this.memo = true; + } + this.loadingDestination = false; this.$scope.$apply(); }) .catch(error => { + console.log(error); let alert; if (this.destinationAddress.indexOf('*') < 0) { alert = new Alert({ @@ -204,6 +210,18 @@ export default class SendWidgetController { this.amountAlertGroup.show(alert); } + // check if the destination requires a memo + if (this.destination in knownAccounts && knownAccounts[this.destination].memo_required && !this.memoValue) { + let alert = new Alert({ + title: '', + text: 'The payment destination (' + knownAccounts[this.destination].name +') requires you to specify a memo to identify your account.', + type: Alert.TYPES.ERROR + }); + this.memoAlertGroup.show(alert); + this.sending = false; + return; + } + if (this.memo) { let memo, memoError; try { diff --git a/known_accounts.es6 b/known_accounts.es6 new file mode 100644 index 0000000..8a65725 --- /dev/null +++ b/known_accounts.es6 @@ -0,0 +1,15 @@ +const knownAccounts = { + 'GCGNWKCJ3KHRLPM3TM6N7D3W5YKDJFL6A2YCXFXNMRTZ4Q66MEMZ6FI2': { + name: 'Poloniex', + memo_required: true + }, + 'GA5XIGA5C7QTPTWXQHY6MCJRMTRZDOSHR6EFIBNDQTCQHG262N4GGKTM': { + name: 'Kraken', + memo_required: true + }, + 'GB6YPGW5JFMMP2QB2USQ33EUWTXVL4ZT5ITUNCY3YKVWOJPP57CANOF3': { + name: 'Bittrex', + memo_required: true + } +}; +export default knownAccounts; From 5384cdec626f8d819d9210f4bed9e3270a9d4623 Mon Sep 17 00:00:00 2001 From: lenondupe Date: Mon, 18 Dec 2017 21:06:20 +0100 Subject: [PATCH 2/6] #48 remove debug logging --- controllers/send-widget.controller.es6 | 1 - 1 file changed, 1 deletion(-) diff --git a/controllers/send-widget.controller.es6 b/controllers/send-widget.controller.es6 index 241171c..918d762 100644 --- a/controllers/send-widget.controller.es6 +++ b/controllers/send-widget.controller.es6 @@ -134,7 +134,6 @@ export default class SendWidgetController { this.$scope.$apply(); }) .catch(error => { - console.log(error); let alert; if (this.destinationAddress.indexOf('*') < 0) { alert = new Alert({ From cf4e8d581af71654b7704db845596d99eac10713 Mon Sep 17 00:00:00 2001 From: lenondupe Date: Tue, 19 Dec 2017 10:25:06 +0100 Subject: [PATCH 3/6] #48 some more known accounts that require memo's --- known_accounts.es6 | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/known_accounts.es6 b/known_accounts.es6 index 8a65725..153ecc6 100644 --- a/known_accounts.es6 +++ b/known_accounts.es6 @@ -10,6 +10,18 @@ const knownAccounts = { 'GB6YPGW5JFMMP2QB2USQ33EUWTXVL4ZT5ITUNCY3YKVWOJPP57CANOF3': { name: 'Bittrex', memo_required: true + }, + 'GB7GRJ5DTE3AA2TCVHQS2LAD3D7NFG7YLTOEWEBVRNUUI2Q3TJ5UQIFM': { + name: 'BTC38', + memo_required: true + }, + 'GBV4ZDEPNQ2FKSPKGJP2YKDAIZWQ2XKRQD4V4ACH3TCTFY6KPY3OAVS7': { + name: 'Changelly', + memo_required: true + }, + 'GC4KAS6W2YCGJGLP633A6F6AKTCV4WSLMTMIQRSEQE5QRRVKSX7THV6S': { + name: 'BitcoinIndonesia', + memo_required: true } }; export default knownAccounts; From 71ede16525ea61635f389d105fe3800e52abff3f Mon Sep 17 00:00:00 2001 From: lenondupe Date: Tue, 19 Dec 2017 15:24:48 +0100 Subject: [PATCH 4/6] #48 don't enforce using memo, but only show a warning. When a known account is entered the memo field is shown and a warning is displayed that the destination requires a memo. Users can opt out of using a memo by clicking 'cancel'. --- controllers/send-widget.controller.es6 | 20 +++++++------------- known_accounts.es6 | 12 ++++++------ 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/controllers/send-widget.controller.es6 b/controllers/send-widget.controller.es6 index 918d762..827924d 100644 --- a/controllers/send-widget.controller.es6 +++ b/controllers/send-widget.controller.es6 @@ -126,8 +126,14 @@ export default class SendWidgetController { this.memoBlocked = false; } - if (this.destination in knownAccounts && knownAccounts[this.destination].memo_required) { + if (this.destination in knownAccounts && knownAccounts[this.destination].requiredMemoType) { this.memo = true; + this.memoType = knownAccounts[this.destination].requiredMemoType; + let alert = new Alert({ + text: 'The payment destination (' + knownAccounts[this.destination].name +') requires you to specify a memo to identify your account.', + type: Alert.TYPES.WARNING + }); + this.memoAlertGroup.show(alert); } this.loadingDestination = false; @@ -209,18 +215,6 @@ export default class SendWidgetController { this.amountAlertGroup.show(alert); } - // check if the destination requires a memo - if (this.destination in knownAccounts && knownAccounts[this.destination].memo_required && !this.memoValue) { - let alert = new Alert({ - title: '', - text: 'The payment destination (' + knownAccounts[this.destination].name +') requires you to specify a memo to identify your account.', - type: Alert.TYPES.ERROR - }); - this.memoAlertGroup.show(alert); - this.sending = false; - return; - } - if (this.memo) { let memo, memoError; try { diff --git a/known_accounts.es6 b/known_accounts.es6 index 153ecc6..f5b88c2 100644 --- a/known_accounts.es6 +++ b/known_accounts.es6 @@ -1,27 +1,27 @@ const knownAccounts = { 'GCGNWKCJ3KHRLPM3TM6N7D3W5YKDJFL6A2YCXFXNMRTZ4Q66MEMZ6FI2': { name: 'Poloniex', - memo_required: true + requiredMemoType: 'MEMO_ID' }, 'GA5XIGA5C7QTPTWXQHY6MCJRMTRZDOSHR6EFIBNDQTCQHG262N4GGKTM': { name: 'Kraken', - memo_required: true + requiredMemoType: 'MEMO_ID' }, 'GB6YPGW5JFMMP2QB2USQ33EUWTXVL4ZT5ITUNCY3YKVWOJPP57CANOF3': { name: 'Bittrex', - memo_required: true + requiredMemoType: 'MEMO_TEXT' }, 'GB7GRJ5DTE3AA2TCVHQS2LAD3D7NFG7YLTOEWEBVRNUUI2Q3TJ5UQIFM': { name: 'BTC38', - memo_required: true + requiredMemoType: 'MEMO_ID' }, 'GBV4ZDEPNQ2FKSPKGJP2YKDAIZWQ2XKRQD4V4ACH3TCTFY6KPY3OAVS7': { name: 'Changelly', - memo_required: true + requiredMemoType: 'MEMO_ID' }, 'GC4KAS6W2YCGJGLP633A6F6AKTCV4WSLMTMIQRSEQE5QRRVKSX7THV6S': { name: 'BitcoinIndonesia', - memo_required: true + requiredMemoType: 'MEMO_TEXT' } }; export default knownAccounts; From 176c6a9afb7fbb716d303dd86f02846e0016cc59 Mon Sep 17 00:00:00 2001 From: lenondupe Date: Thu, 21 Dec 2017 14:11:42 +0100 Subject: [PATCH 5/6] #48 separate alert group for warning of missing memo enables us to clear out warning if destination is changed and on the other hand keep the warning if it is not changed (if user navigates back to sendSetup screen from confirm screen) --- controllers/send-widget.controller.es6 | 25 ++++++++++++++++--------- templates/send-widget.template.html | 11 ++++++++--- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/controllers/send-widget.controller.es6 b/controllers/send-widget.controller.es6 index 827924d..f1193cd 100644 --- a/controllers/send-widget.controller.es6 +++ b/controllers/send-widget.controller.es6 @@ -65,11 +65,17 @@ export default class SendWidgetController { }); Alerts.registerGroup(this.amountAlertGroup); - this.memoAlertGroup = new AlertGroup(); - this.memoAlertGroup.registerUpdateListener(alerts => { - this.memoAlerts = alerts; + this.memoErrorAlertGroup = new AlertGroup(); + this.memoErrorAlertGroup.registerUpdateListener(alerts => { + this.memoErrorAlerts = alerts; }); - Alerts.registerGroup(this.memoAlertGroup); + Alerts.registerGroup(this.memoErrorAlertGroup); + + this.memoWarningAlertGroup = new AlertGroup(); + this.memoWarningAlertGroup.registerUpdateListener(alerts => { + this.memoWarningAlerts = alerts; + }); + Alerts.registerGroup(this.memoWarningAlertGroup); this.useLedger = this.session.data && this.session.data['useLedger']; this.bip32Path = this.session.data && this.session.data['bip32Path']; @@ -78,6 +84,7 @@ export default class SendWidgetController { loadDestination($event) { this.loadingDestination = true; this.addressAlertGroup.clear(); + this.memoWarningAlertGroup.clear(); let resetState = () => { this.destination = null; @@ -133,7 +140,7 @@ export default class SendWidgetController { text: 'The payment destination (' + knownAccounts[this.destination].name +') requires you to specify a memo to identify your account.', type: Alert.TYPES.WARNING }); - this.memoAlertGroup.show(alert); + this.memoWarningAlertGroup.show(alert); } this.loadingDestination = false; @@ -171,7 +178,7 @@ export default class SendWidgetController { if ($event) { $event.preventDefault(); } - this.memoAlertGroup.clear(); + this.memoErrorAlertGroup.clear(); this.memo = false; this.memoType = null; this.memoValue = null; @@ -194,7 +201,7 @@ export default class SendWidgetController { this.addressAlertGroup.clear(); this.amountAlertGroup.clear(); - this.memoAlertGroup.clear(); + this.memoErrorAlertGroup.clear(); if (!Account.isValidAccountId(this.destination)) { let alert = new Alert({ @@ -242,11 +249,11 @@ export default class SendWidgetController { text: memoError, type: Alert.TYPES.ERROR }); - this.memoAlertGroup.show(alert); + this.memoErrorAlertGroup.show(alert); } } - if (this.addressAlerts.length || this.amountAlerts.length || this.memoAlerts.length) { + if (this.addressAlerts.length || this.amountAlerts.length || this.memoErrorAlerts.length) { this.sending = false; return; } diff --git a/templates/send-widget.template.html b/templates/send-widget.template.html index db97add..35f388c 100644 --- a/templates/send-widget.template.html +++ b/templates/send-widget.template.html @@ -65,7 +65,7 @@

Send lumens

@@ -75,8 +75,13 @@

Send lumens

Note: The specified federation address requires this transaction's memo to be a certain value. -
- +
+ + {{alert.title}} {{alert.text}} + +
+
+ {{alert.title}} {{alert.text}}
From 75fb8f2146565fdfa2f8275207234b34d7615b21 Mon Sep 17 00:00:00 2001 From: lenondupe Date: Thu, 21 Dec 2017 15:01:46 +0100 Subject: [PATCH 6/6] #48 clear all memo-related info on transaction success and show the memo warning on the confirmation screen as well if it is missing for a known account --- controllers/send-widget.controller.es6 | 3 +++ templates/send-widget.template.html | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/controllers/send-widget.controller.es6 b/controllers/send-widget.controller.es6 index f1193cd..02db342 100644 --- a/controllers/send-widget.controller.es6 +++ b/controllers/send-widget.controller.es6 @@ -433,7 +433,10 @@ export default class SendWidgetController { this.destination = null; this.amount = null; this.memo = false; + this.memoType = null; + this.memoValue = null; this.lastTransactionXDR = null; + this.memoWarningAlertGroup.clear(); this.$rootScope.$broadcast('account-viewer.transaction-success'); } diff --git a/templates/send-widget.template.html b/templates/send-widget.template.html index 35f388c..e304000 100644 --- a/templates/send-widget.template.html +++ b/templates/send-widget.template.html @@ -110,6 +110,12 @@

Send lumens

{{widget.memoValue}}
+
+ + {{alert.title}} {{alert.text}} + +
+