diff --git a/controllers/send-widget.controller.es6 b/controllers/send-widget.controller.es6 index 8476ce9..02db342 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') @@ -64,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']; @@ -77,6 +84,7 @@ export default class SendWidgetController { loadDestination($event) { this.loadingDestination = true; this.addressAlertGroup.clear(); + this.memoWarningAlertGroup.clear(); let resetState = () => { this.destination = null; @@ -123,8 +131,18 @@ export default class SendWidgetController { this.memoBlocked = true; } else { this.memoBlocked = false; - } + + 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.memoWarningAlertGroup.show(alert); + } + this.loadingDestination = false; this.$scope.$apply(); }) @@ -160,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; @@ -183,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({ @@ -231,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; } @@ -415,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/known_accounts.es6 b/known_accounts.es6 new file mode 100644 index 0000000..f5b88c2 --- /dev/null +++ b/known_accounts.es6 @@ -0,0 +1,27 @@ +const knownAccounts = { + 'GCGNWKCJ3KHRLPM3TM6N7D3W5YKDJFL6A2YCXFXNMRTZ4Q66MEMZ6FI2': { + name: 'Poloniex', + requiredMemoType: 'MEMO_ID' + }, + 'GA5XIGA5C7QTPTWXQHY6MCJRMTRZDOSHR6EFIBNDQTCQHG262N4GGKTM': { + name: 'Kraken', + requiredMemoType: 'MEMO_ID' + }, + 'GB6YPGW5JFMMP2QB2USQ33EUWTXVL4ZT5ITUNCY3YKVWOJPP57CANOF3': { + name: 'Bittrex', + requiredMemoType: 'MEMO_TEXT' + }, + 'GB7GRJ5DTE3AA2TCVHQS2LAD3D7NFG7YLTOEWEBVRNUUI2Q3TJ5UQIFM': { + name: 'BTC38', + requiredMemoType: 'MEMO_ID' + }, + 'GBV4ZDEPNQ2FKSPKGJP2YKDAIZWQ2XKRQD4V4ACH3TCTFY6KPY3OAVS7': { + name: 'Changelly', + requiredMemoType: 'MEMO_ID' + }, + 'GC4KAS6W2YCGJGLP633A6F6AKTCV4WSLMTMIQRSEQE5QRRVKSX7THV6S': { + name: 'BitcoinIndonesia', + requiredMemoType: 'MEMO_TEXT' + } +}; +export default knownAccounts; diff --git a/templates/send-widget.template.html b/templates/send-widget.template.html index db97add..e304000 100644 --- a/templates/send-widget.template.html +++ b/templates/send-widget.template.html @@ -65,7 +65,7 @@