Skip to content
This repository has been archived by the owner on Nov 30, 2020. It is now read-only.

Commit

Permalink
Merge pull request #49 from lenondupe/master
Browse files Browse the repository at this point in the history
Warn of payments to exchanges without memo #48
  • Loading branch information
bartekn authored Dec 21, 2017
2 parents 572e725 + 75fb8f2 commit a0ea183
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 12 deletions.
39 changes: 30 additions & 9 deletions controllers/send-widget.controller.es6
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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'];
Expand All @@ -77,6 +84,7 @@ export default class SendWidgetController {
loadDestination($event) {
this.loadingDestination = true;
this.addressAlertGroup.clear();
this.memoWarningAlertGroup.clear();

let resetState = () => {
this.destination = null;
Expand Down Expand Up @@ -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();
})
Expand Down Expand Up @@ -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;
Expand All @@ -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({
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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');
}

Expand Down
27 changes: 27 additions & 0 deletions known_accounts.es6
Original file line number Diff line number Diff line change
@@ -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;
17 changes: 14 additions & 3 deletions templates/send-widget.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ <h2 class="sendPane__title">Send lumens</h2>
<input ng-model="widget.memoValue"
ng-disabled="widget.memoBlocked"
class="sendSetup__memo__memoSetup__input"
ng-class="{'s-inputAlert--alert': widget.memoAlerts.length > 0, 'is-disabled': widget.memoBlocked}"
ng-class="{'s-inputAlert--alert': widget.memoErrorAlerts.length > 0, 'is-disabled': widget.memoBlocked}"
placeholder="{{widget.memoPlaceholder}}" type="text" />
</div>
</div>
Expand All @@ -75,8 +75,13 @@ <h2 class="sendPane__title">Send lumens</h2>
<strong>Note</strong>: The specified federation address requires this transaction's memo to be a certain value.
</span>
</div>
<div class="s-alert s-alert--alert sendSetup__error" ng-if="widget.memoAlerts.length > 0">
<span ng-repeat="alert in widget.memoAlerts">
<div class="s-alert s-alert--alert sendSetup__error" ng-if="widget.memoErrorAlerts.length > 0">
<span ng-repeat="alert in widget.memoErrorAlerts">
{{alert.title}} {{alert.text}}
</span>
</div>
<div class="s-alert s-alert--warning sendSetup__error" ng-if="widget.memoWarningAlerts.length > 0">
<span ng-repeat="alert in widget.memoWarningAlerts">
{{alert.title}} {{alert.text}}
</span>
</div>
Expand Down Expand Up @@ -105,6 +110,12 @@ <h2 class="sendPane__title">Send lumens</h2>
<span class="sendConfirm__sendingContainer__amount__info">{{widget.memoValue}}</span>
</div>
</div>
<div class="s-alert s-alert--warning" ng-if="!widget.memo && widget.memoWarningAlerts.length > 0">
<span ng-repeat="alert in widget.memoWarningAlerts">
{{alert.title}} {{alert.text}}
</span>
</div>


<button class="s-button sendConfirm__submit" ng-click="widget.confirm()">Submit transaction</button>

Expand Down

0 comments on commit a0ea183

Please sign in to comment.