From e737446cee095821305dfb3fb00b903f9add338e Mon Sep 17 00:00:00 2001 From: okanishcheva Date: Mon, 19 Aug 2019 16:19:07 +0300 Subject: [PATCH 01/18] DEXW-1239: save --- .../components/singleSend/SingleSend.js | 745 +---------------- .../singleSend/bankSend/BankSend.js | 28 + .../singleSend/bankSend/bank-send.html | 2 + .../singleSend/gatewaySend/GatewaySend.js | 768 ++++++++++++++++++ .../singleSend/gatewaySend/gateway-send.html | 0 .../components/singleSend/single-send.html | 330 +------- .../singleSend/wavesSend/WavesSend.js | 668 +++++++++++++++ .../singleSend/wavesSend/waves-send.html | 128 +++ 8 files changed, 1618 insertions(+), 1051 deletions(-) create mode 100644 src/modules/utils/modals/sendAsset/components/singleSend/bankSend/BankSend.js create mode 100644 src/modules/utils/modals/sendAsset/components/singleSend/bankSend/bank-send.html create mode 100644 src/modules/utils/modals/sendAsset/components/singleSend/gatewaySend/GatewaySend.js create mode 100644 src/modules/utils/modals/sendAsset/components/singleSend/gatewaySend/gateway-send.html create mode 100644 src/modules/utils/modals/sendAsset/components/singleSend/wavesSend/WavesSend.js create mode 100644 src/modules/utils/modals/sendAsset/components/singleSend/wavesSend/waves-send.html diff --git a/src/modules/utils/modals/sendAsset/components/singleSend/SingleSend.js b/src/modules/utils/modals/sendAsset/components/singleSend/SingleSend.js index 44a09b69d8..a1a2d3e110 100644 --- a/src/modules/utils/modals/sendAsset/components/singleSend/SingleSend.js +++ b/src/modules/utils/modals/sendAsset/components/singleSend/SingleSend.js @@ -1,734 +1,21 @@ (function () { 'use strict'; - const FIAT_ASSETS = { - [WavesApp.defaultAssets.USD]: true, - [WavesApp.defaultAssets.EUR]: true, - [WavesApp.defaultAssets.TRY]: true - }; - - const { Money } = require('@waves/data-entities'); - const { BigNumber } = require('@waves/bignumber'); - const ds = require('data-service'); - const { SIGN_TYPE } = require('@waves/signature-adapter'); - const analytics = require('@waves/event-sender'); - - const BANK_RECIPIENT = WavesApp.bankRecipient; - const MIN_TOKEN_COUNT = 100; - const MAX_TOKEN_COUNT = 50000; - - /** - * @param {Base} Base - * @param {$rootScope.Scope} $scope - * @param {app.utils} utils - * @param {IPollCreate} createPoll - * @param {ConfigService} configService - * @param {IOuterBlockchains} outerBlockchains - * @param {User} user - * @param {GatewayService} gatewayService - * @param {Waves} waves - */ - const controller = function (Base, - $scope, - utils, - createPoll, - waves, - configService, - outerBlockchains, - user, - gatewayService) { - - class SingleSend extends Base { - - /** - * @return {boolean} - */ - get hasSendToBank() { - return FIAT_ASSETS[this.assetId] || false; - } - - /** - * @return {boolean} - */ - get isLira() { - return this.assetId === WavesApp.defaultAssets.TRY; - } - - /** - * @return {ISingleSendTx} - */ - get tx() { - return this.state.singleSend; - } - - /** - * @return {string} - */ - get assetId() { - return this.state.assetId; - } - - set assetId(id) { - this.state.assetId = id; - } - - /** - * @return {string} - */ - get mirrorId() { - return this.state.mirrorId; - } + const controller = function () { - /** - * @return {Object} - */ - get moneyHash() { - return this.state.moneyHash; - } + class SingleSend { /** - * @return {Object.} + * @type {ISendMode} */ - get feeHash() { - return utils.groupMoney(this.feeList || []); - } - - /** - * @return {Money} - */ - get balance() { - return this.moneyHash[this.assetId]; - } - - /** - * @return {boolean} - */ - get outerSendMode() { - return this.state.outerSendMode; - } - - set outerSendMode(value) { - this.state.outerSendMode = value; - } - - /** - * @return {string} - */ - get paymentId() { - return this.state.paymentId; - } - - set paymentId(value) { - this.state.paymentId = value; - } - - /** - * @return {IGatewayDetails} - */ - get gatewayDetails() { - return this.state.gatewayDetails; - } - - set gatewayDetails(value) { - this.state.gatewayDetails = value; - } - - get isBankPending() { - return this.toBankMode && this.termsIsPending; - } - - get isBankError() { - return this.toBankMode && this.termsLoadError; - } - - get isGatewayAccepted() { - return !configService - .get('PERMISSIONS.CANT_TRANSFER_GATEWAY').includes(this.balance.asset.id); - } - - get isBankAccepted() { - return this.toBankMode ? this.isGatewayAccepted : true; - } - - get isBankPendingOrError() { - return this.isBankError || this.isBankPending; - } - - get hasOuterError() { - return this.outerSendMode && this.gatewayError || this.isBankError; - } - - get minimumAmount() { - return this.gatewayDetails && - this.gatewayDetails.minimumAmount || - this.toBankMode && - new BigNumber(MIN_TOKEN_COUNT); - } - - get maximumAmount() { - return this.maxGatewayAmount || this.toBankMode && this.balance.cloneWithTokens(MAX_TOKEN_COUNT); - } - - /** - * @type {string} - */ - txType = WavesApp.TRANSACTION_TYPES.NODE.TRANSFER; - - /** - * @type {boolean} - */ - get toBankMode() { - return this.state.toBankMode; - } - - set toBankMode(value) { - this.state.toBankMode = value; - } - - /** - * @type {string} - */ - digiLiraUserLink = 'https://www.digilira.com/'; - /** - * @type {Function} - */ - onContinue = null; - /** - * @type {string} - */ - focus = null; - /** - * @type {Money} - */ - mirror = null; - /** - * @type {boolean} - */ - noMirror = false; - /** - * @type {boolean} - */ - hasComission = true; - /** - * @type {Array} - */ - feeList = null; - /** - * @type {Money} - */ - minAmount = null; - /** - * @type {Money} - */ - maxAmount = null; - /** - * @type {ISendState} - */ - state = Object.create(null); - /** - * @type {Money} - */ - maxGatewayAmount = null; - /** - * @type {boolean} - */ - gatewayDetailsError = false; - /** - * @type {boolean} - */ - gatewayAddressError = false; - /** - * @type {boolean} - */ - gatewayWrongAddress = false; - /** - * @type {boolean} - */ - gatewayError = false; - /** - * @type {boolean} - */ - termsIsPending = true; - /** - * @type {boolean} - */ - termsLoadError = false; - /** - * @type {boolean} - */ - signInProgress = false; - /** - * @type {ISingleSendTx} - */ - wavesTx = { - type: SIGN_TYPE.TRANSFER, - amount: null, - attachment: '', - fee: null, - recipient: '', - assetId: '' - }; - /** - * @type {boolean} - * @private - */ - _noCurrentRate = false; + sendMode = 'waves'; constructor() { - super(); - - $scope.WavesApp = WavesApp; - } - - $postLink() { - this.receive(utils.observe(this.tx, 'fee'), this._currentHasCommission, this); - const onHasMoneyHash = () => { - this.receive(utils.observe(this.state, 'toBankMode'), this._onChangeBankMode, this); - this.observe('gatewayDetails', this._currentHasCommission); - - this.minAmount = this.state.moneyHash[this.state.assetId].cloneWithTokens('0'); - this.tx.amount = this.tx.amount || this.moneyHash[this.assetId].cloneWithTokens('0'); - this._fillMirror(); - - this.receive(utils.observe(this.state, 'assetId'), this._onChangeAssetId, this); - this.receive(utils.observe(this.state, 'mirrorId'), this._onChangeMirrorId, this); - - this.receive(utils.observe(this.state, 'paymentId'), this._updateGatewayDetails, this); - this.receive(utils.observe(this.tx, 'recipient'), this._updateGatewayDetails, this); - - this.receive(utils.observe(this.state, 'paymentId'), this._updateGatewayPermisson, this); - this.receive(utils.observe(this.tx, 'recipient'), this._updateGatewayPermisson, this); - - this.receive(utils.observe(this.tx, 'amount'), this._onChangeAmount, this); - - this.observe('gatewayDetails', this._updateWavesTxObject); - this.receive(utils.observe(this.tx, 'amount'), this._updateWavesTxObject, this); - this.receive(utils.observe(this.tx, 'recipient'), this._updateWavesTxObject, this); - this.receive(utils.observe(this.tx, 'attachment'), this._updateWavesTxObject, this); - - this.observe('mirror', this._onChangeAmountMirror); - this.observe(['gatewayAddressError', 'gatewayDetailsError', 'gatewayWrongAddress'], - this._updateGatewayError); - - this._currentHasCommission(); - this._onChangeBaseAssets(); - this._updateGatewayDetails(); - this._updateGatewayPermisson(); - }; - if (!this.state.moneyHash) { - this.receiveOnce(utils.observe(this.state, 'moneyHash'), onHasMoneyHash); - } else { - onHasMoneyHash(); - } - this.receive(utils.observe(this.state, 'moneyHash'), () => { - this._currentHasCommission(); - this._onChangeBaseAssets(); - this._updateGatewayDetails(); - }); - this._onChangeBaseAssets(); - this._updateWavesTxObject(); - } - - onSignCoinomatStart() { - this.signInProgress = true; - } - - onSignCoinomatEnd() { - this.signInProgress = false; - } - - createTx() { - const toGateway = this.outerSendMode && this.gatewayDetails; - const fee = toGateway ? this.tx.amount.cloneWithTokens(toGateway.gatewayFee) : null; - const attachmentString = this.tx.attachment ? this.tx.attachment.toString() : ''; - const tx = waves.node.transactions.createTransaction({ - ...this.tx, - recipient: toGateway ? this.gatewayDetails.address : this.tx.recipient, - attachment: utils.stringToBytes(toGateway ? this.gatewayDetails.attachment : attachmentString), - amount: toGateway ? this.tx.amount.add(fee) : this.tx.amount - }); - - const signable = ds.signature.getSignatureApi().makeSignable({ - type: tx.type, - data: tx - }); - - return signable; - } - - onSignTx(signable) { - analytics.send({ name: 'Transfer Continue Click', target: 'ui' }); - this.onContinue({ signable }); - } - - fillMax() { - let amount = null; - const moneyHash = utils.groupMoney(this.feeList); - if (moneyHash[this.assetId]) { - amount = this.balance.sub(moneyHash[this.assetId]); - } else { - amount = this.balance; - } - - if (amount.getTokens().lt(0)) { - amount = this.moneyHash[this.assetId].cloneWithTokens('0'); - } - - waves.utils.getRate(this.assetId, this.mirrorId).then(rate => { - this._noCurrentRate = true; - this.mirror = amount.convertTo(this.moneyHash[this.mirrorId].asset, rate); - this.tx.amount = amount; - this._noCurrentRate = false; - $scope.$apply(); - }); - } - - onBlurMirror() { - if (!this.mirror) { - this._fillMirror(); - } - this.focus = ''; + this.test = 0; } - /** - * @param {string} url - * @return {null} - */ - onReadQrCode(url) { - if (!url.includes('https://')) { - this.tx.recipient = url; - $scope.$apply(); - return null; - } - - const routeData = utils.getRouterParams(utils.getUrlForRoute(url)); - - if (!routeData || routeData.name !== 'SEND_ASSET') { - return null; - } - - const result = routeData.data; - - this.tx.recipient = result.recipient; - - // analytics.push('Send', `Send.QrCodeRead.${WavesApp.type}`, - // `Send.QrCodeRead.${WavesApp.type}.Success`); - - if (result) { - - const applyAmount = () => { - if (result.amount) { - this.tx.amount = this.moneyHash[this.assetId].cloneWithTokens(result.amount); - this._fillMirror(); - } - $scope.$apply(); - }; - - result.assetId = result.asset || result.assetId; - - if (result.assetId) { - waves.node.assets.balance(result.assetId).then(({ available }) => { - this.moneyHash[available.asset.id] = available; - - if (this.assetId !== available.asset.id) { - const myAssetId = this.assetId; - this.assetId = available.asset.id; - this.canChooseAsset = true; - // TODO fix (hack for render asset avatar) - this.choosableMoneyList = [this.moneyHash[myAssetId], available]; - } - - applyAmount(); - }, applyAmount); - } else { - applyAmount(); - } - } - } - - /** - * @return {boolean} - */ - isMoneroNotIntegratedAddress() { - const moneroAddressLength = 95; - const assetIsMonero = this.state.assetId === WavesApp.defaultAssets.XMR; - return assetIsMonero && this.tx.recipient.length === moneroAddressLength; - } - - getGatewayDetails() { - this._onChangeAssetId(); - } - - /** - * @private - */ - _updateWavesTxObject() { - const toGateway = this.outerSendMode && this.gatewayDetails; - const fee = toGateway ? this.tx.amount.cloneWithTokens(toGateway.gatewayFee) : null; - const attachmentString = this.tx.attachment ? this.tx.attachment.toString() : ''; - const isWavesAddress = user.isValidAddress(this.tx.recipient); - this.wavesTx = { - ...this.wavesTx, - recipient: toGateway ? this.gatewayDetails.address : isWavesAddress && this.tx.recipient || '', - attachment: utils.stringToBytes(toGateway ? this.gatewayDetails.attachment : attachmentString), - amount: toGateway ? this.tx.amount.add(fee) : this.tx.amount, - assetId: this.assetId - }; - } - - /** - * @private - */ - _validateForm() { - if (this.tx.amount.getTokens().gt(0) || this.tx.recipient) { - this.send.$setDirty(true); - this.send.$setSubmitted(true); - } - } - - /** - * @private - */ - _onChangeBankMode() { - if (this.toBankMode && !this.isLira) { - this.tx.recipient = BANK_RECIPIENT; - this.termsIsPending = true; - } else { - this.tx.recipient = ''; - this.termsIsPending = false; - } - - this._setMinAmount(); - this._updateGatewayPermisson(); - } - - /** - * @private - */ - _setMinAmount() { - if (this.toBankMode && !this.isLira) { - const maxCoinomatAmount = this.balance.cloneWithTokens(50000); - const minCoinomatAmount = this.balance.cloneWithTokens(100); - - this.maxAmount = Money.min(maxCoinomatAmount, this.balance); - this.minAmount = minCoinomatAmount; - } else { - this.minAmount = this.state.moneyHash[this.assetId].cloneWithTokens('0'); - this.maxAmount = this.moneyHash[this.assetId]; - } - - this._validateForm(); - } - - /** - * @private - */ - _onChangeMirrorId() { - if (!this.mirrorId) { - throw new Error('Has no asset id!'); - } - - this._onChangeBaseAssets(); - - if (!this.moneyHash[this.mirrorId]) { - return null; - } - - this.mirror = this.moneyHash[this.mirrorId].cloneWithTokens('0'); - this._onChangeAmount(); - } - - /** - * @private - */ - _onChangeAssetId() { - if (!this.assetId) { - throw new Error('Has no asset id!'); - } - - this._onChangeBaseAssets(); - - if (!this.moneyHash[this.assetId]) { - return null; - } - - this.tx.amount = this.moneyHash[this.assetId].cloneWithTokens('0'); - this.mirror = this.moneyHash[this.mirrorId].cloneWithTokens('0'); - this._updateGatewayDetails(); - this._updateGatewayPermisson(); - } - - /** - * @private - */ - _currentHasCommission() { - if (!this.moneyHash) { - return null; - } - - const details = this.gatewayDetails; - - const check = (feeList) => { - const feeHash = utils.groupMoney(feeList); - const balanceHash = this.moneyHash; - - this.hasComission = Object.keys(feeHash).every((feeAssetId) => { - const fee = feeHash[feeAssetId]; - return balanceHash[fee.asset.id] && balanceHash[fee.asset.id].gte(fee); - }); - }; - - if (details) { - const gatewayFee = this.balance.cloneWithTokens(details.gatewayFee); - this.feeList = [this.tx.fee, gatewayFee]; - check(this.feeList.concat(this.balance.cloneWithTokens(details.minimumAmount))); - } else { - this.feeList = [this.tx.fee]; - check(this.feeList); - } - } - - /** - * @private - */ - _onChangeBaseAssets() { - if (this.assetId === this.mirrorId) { - this.noMirror = true; - } else { - waves.utils.getRate(this.assetId, this.mirrorId).then((rate) => { - this.noMirror = rate.eq(0); - }); - } - } - - /** - * @private - */ - _onChangeAmount() { - if (!this._noCurrentRate && !this.noMirror && this.focus === 'amount') { - this._fillMirror(); - } - - } - - /** - * @private - */ - _onChangeAmountMirror() { - if (!this._noCurrentRate && this.focus === 'mirror') { - this._fillAmount(); - } - } - - /** - * @private - */ - _fillMirror() { - - if (!this.tx.amount) { - this.mirror = null; - setTimeout(() => $scope.$digest(), 0); - return null; - } - - waves.utils.getRate(this.assetId, this.mirrorId).then((rate) => { - this.mirror = this.tx.amount.convertTo(this.moneyHash[this.mirrorId].asset, rate); - $scope.$digest(); - }); - } - - /** - * @private - */ - _fillAmount() { - - if (!this.mirror) { - this.tx.amount = null; - setTimeout(() => $scope.$digest(), 0); - return null; - } - - waves.utils.getRate(this.mirrorId, this.assetId).then((rate) => { - this.tx.amount = this.mirror.convertTo(this.moneyHash[this.assetId].asset, rate); - $scope.$digest(); - }); - } - - /** - * @private - */ - _updateGatewayDetails() { - if (this.toBankMode && !this.isLira) { - this._setMinAmount(); - return; - } - - const outerChain = outerBlockchains[this.assetId]; - const isValidWavesAddress = user.isValidAddress(this.tx.recipient); - - if (this.gatewayDetailsError) { - this.outerSendMode = false; - this.gatewayDetailsError = false; - } - - if (this.gatewayAddressError) { - this.gatewayAddressError = false; - } - - if (this.gatewayWrongAddress) { - this.gatewayWrongAddress = false; - } - - this.outerSendMode = !isValidWavesAddress && outerChain && outerChain.isValidAddress(this.tx.recipient); - - if (this.outerSendMode) { - return gatewayService.getWithdrawDetails(this.balance.asset, this.tx.recipient, this.paymentId) - .then((details) => { - const max = BigNumber.min( - details.maximumAmount.add(details.gatewayFee), - this.moneyHash[this.assetId].getTokens() - ); - - this.gatewayDetails = details; - this.minAmount = this.moneyHash[this.assetId] - .cloneWithTokens(details.minimumAmount.sub('0.00000001')); - this.maxAmount = this.moneyHash[this.assetId].cloneWithTokens(max); - this.maxGatewayAmount = Money.fromTokens(details.maximumAmount, this.balance.asset); - $scope.$apply(); - }, (e) => { - this.gatewayDetails = null; - if (e.message === gatewayService.getAddressErrorMessage(this.balance.asset, - this.tx.recipient, 'errorAddressMessage')) { - this.gatewayAddressError = true; - } else if (e.message === gatewayService.getWrongAddressMessage(this.balance.asset, - this.tx.recipient, 'wrongAddressMessage')) { - this.gatewayWrongAddress = true; - } else { - this.gatewayDetailsError = true; - } - $scope.$apply(); - }); - } else { - this.minAmount = this.state.moneyHash[this.assetId].cloneWithTokens('0'); - this.maxAmount = this.moneyHash[this.assetId]; - this.gatewayDetails = null; - this._validateForm(); - } - return Promise.resolve(); - } - - /** - * @private - */ - _updateGatewayPermisson() { - this.gatewayDetailsError = this.outerSendMode ? !this.isGatewayAccepted : this.gatewayDetailsError; - } - - /** - * @private - */ - _updateGatewayError() { - this.gatewayError = this.gatewayAddressError || this.gatewayDetailsError || this.gatewayWrongAddress; + onChangeMode(mode) { + this.sendMode = mode; } } @@ -736,17 +23,7 @@ return new SingleSend(); }; - controller.$inject = [ - 'Base', - '$scope', - 'utils', - 'createPoll', - 'waves', - 'configService', - 'outerBlockchains', - 'user', - 'gatewayService' - ]; + controller.$inject = []; angular.module('app.ui').component('wSingleSend', { bindings: { @@ -760,9 +37,5 @@ })(); /** - * @typedef {object} ISendTx - * @property {Money} fee - * @property {Money} amount - * @property {string} recipient - * @property {string} attachment + * @typedef {string} ISendMode = waves | bank | gateway */ diff --git a/src/modules/utils/modals/sendAsset/components/singleSend/bankSend/BankSend.js b/src/modules/utils/modals/sendAsset/components/singleSend/bankSend/BankSend.js new file mode 100644 index 0000000000..494813404f --- /dev/null +++ b/src/modules/utils/modals/sendAsset/components/singleSend/bankSend/BankSend.js @@ -0,0 +1,28 @@ +(function () { + 'use strict'; + + const controller = function () { + + class BankSend { + + constructor() { + this.test = 0; + } + + } + + return new BankSend(); + }; + + controller.$inject = []; + + angular.module('app.ui').component('wBankSend', { + bindings: { + state: '<', + onContinue: '&' + }, + templateUrl: 'modules/utils/modals/sendAsset/components/singleSend/bankSend/bank-send.html', + transclude: true, + controller + }); +})(); diff --git a/src/modules/utils/modals/sendAsset/components/singleSend/bankSend/bank-send.html b/src/modules/utils/modals/sendAsset/components/singleSend/bankSend/bank-send.html new file mode 100644 index 0000000000..103be5fa4a --- /dev/null +++ b/src/modules/utils/modals/sendAsset/components/singleSend/bankSend/bank-send.html @@ -0,0 +1,2 @@ +Bank send + diff --git a/src/modules/utils/modals/sendAsset/components/singleSend/gatewaySend/GatewaySend.js b/src/modules/utils/modals/sendAsset/components/singleSend/gatewaySend/GatewaySend.js new file mode 100644 index 0000000000..b08d2ee1e8 --- /dev/null +++ b/src/modules/utils/modals/sendAsset/components/singleSend/gatewaySend/GatewaySend.js @@ -0,0 +1,768 @@ +(function () { + 'use strict'; + + const FIAT_ASSETS = { + [WavesApp.defaultAssets.USD]: true, + [WavesApp.defaultAssets.EUR]: true, + [WavesApp.defaultAssets.TRY]: true + }; + + const { Money } = require('@waves/data-entities'); + const { BigNumber } = require('@waves/bignumber'); + const ds = require('data-service'); + const { SIGN_TYPE } = require('@waves/signature-adapter'); + const analytics = require('@waves/event-sender'); + + const BANK_RECIPIENT = WavesApp.bankRecipient; + const MIN_TOKEN_COUNT = 100; + const MAX_TOKEN_COUNT = 50000; + + /** + * @param {Base} Base + * @param {$rootScope.Scope} $scope + * @param {app.utils} utils + * @param {IPollCreate} createPoll + * @param {ConfigService} configService + * @param {IOuterBlockchains} outerBlockchains + * @param {User} user + * @param {GatewayService} gatewayService + * @param {Waves} waves + */ + const controller = function (Base, + $scope, + utils, + createPoll, + waves, + configService, + outerBlockchains, + user, + gatewayService) { + + class GatewaySend extends Base { + + /** + * @return {boolean} + */ + get hasSendToBank() { + return FIAT_ASSETS[this.assetId] || false; + } + + /** + * @return {boolean} + */ + get isLira() { + return this.assetId === WavesApp.defaultAssets.TRY; + } + + /** + * @return {ISingleSendTx} + */ + get tx() { + return this.state.singleSend; + } + + /** + * @return {string} + */ + get assetId() { + return this.state.assetId; + } + + set assetId(id) { + this.state.assetId = id; + } + + /** + * @return {string} + */ + get mirrorId() { + return this.state.mirrorId; + } + + /** + * @return {Object} + */ + get moneyHash() { + return this.state.moneyHash; + } + + /** + * @return {Object.} + */ + get feeHash() { + return utils.groupMoney(this.feeList || []); + } + + /** + * @return {Money} + */ + get balance() { + return this.moneyHash[this.assetId]; + } + + /** + * @return {boolean} + */ + get outerSendMode() { + return this.state.outerSendMode; + } + + set outerSendMode(value) { + this.state.outerSendMode = value; + } + + /** + * @return {string} + */ + get paymentId() { + return this.state.paymentId; + } + + set paymentId(value) { + this.state.paymentId = value; + } + + /** + * @return {IGatewayDetails} + */ + get gatewayDetails() { + return this.state.gatewayDetails; + } + + set gatewayDetails(value) { + this.state.gatewayDetails = value; + } + + get isBankPending() { + return this.toBankMode && this.termsIsPending; + } + + get isBankError() { + return this.toBankMode && this.termsLoadError; + } + + get isGatewayAccepted() { + return !configService + .get('PERMISSIONS.CANT_TRANSFER_GATEWAY').includes(this.balance.asset.id); + } + + get isBankAccepted() { + return this.toBankMode ? this.isGatewayAccepted : true; + } + + get isBankPendingOrError() { + return this.isBankError || this.isBankPending; + } + + get hasOuterError() { + return this.outerSendMode && this.gatewayError || this.isBankError; + } + + get minimumAmount() { + return this.gatewayDetails && + this.gatewayDetails.minimumAmount || + this.toBankMode && + new BigNumber(MIN_TOKEN_COUNT); + } + + get maximumAmount() { + return this.maxGatewayAmount || this.toBankMode && this.balance.cloneWithTokens(MAX_TOKEN_COUNT); + } + + /** + * @type {string} + */ + txType = WavesApp.TRANSACTION_TYPES.NODE.TRANSFER; + + /** + * @type {boolean} + */ + get toBankMode() { + return this.state.toBankMode; + } + + set toBankMode(value) { + this.state.toBankMode = value; + } + + /** + * @type {string} + */ + digiLiraUserLink = 'https://www.digilira.com/'; + /** + * @type {Function} + */ + onContinue = null; + /** + * @type {string} + */ + focus = null; + /** + * @type {Money} + */ + mirror = null; + /** + * @type {boolean} + */ + noMirror = false; + /** + * @type {boolean} + */ + hasComission = true; + /** + * @type {Array} + */ + feeList = null; + /** + * @type {Money} + */ + minAmount = null; + /** + * @type {Money} + */ + maxAmount = null; + /** + * @type {ISendState} + */ + state = Object.create(null); + /** + * @type {Money} + */ + maxGatewayAmount = null; + /** + * @type {boolean} + */ + gatewayDetailsError = false; + /** + * @type {boolean} + */ + gatewayAddressError = false; + /** + * @type {boolean} + */ + gatewayWrongAddress = false; + /** + * @type {boolean} + */ + gatewayError = false; + /** + * @type {boolean} + */ + termsIsPending = true; + /** + * @type {boolean} + */ + termsLoadError = false; + /** + * @type {boolean} + */ + signInProgress = false; + /** + * @type {ISingleSendTx} + */ + wavesTx = { + type: SIGN_TYPE.TRANSFER, + amount: null, + attachment: '', + fee: null, + recipient: '', + assetId: '' + }; + /** + * @type {boolean} + * @private + */ + _noCurrentRate = false; + + constructor() { + super(); + + $scope.WavesApp = WavesApp; + } + + $postLink() { + this.receive(utils.observe(this.tx, 'fee'), this._currentHasCommission, this); + const onHasMoneyHash = () => { + this.receive(utils.observe(this.state, 'toBankMode'), this._onChangeBankMode, this); + this.observe('gatewayDetails', this._currentHasCommission); + + this.minAmount = this.state.moneyHash[this.state.assetId].cloneWithTokens('0'); + this.tx.amount = this.tx.amount || this.moneyHash[this.assetId].cloneWithTokens('0'); + this._fillMirror(); + + this.receive(utils.observe(this.state, 'assetId'), this._onChangeAssetId, this); + this.receive(utils.observe(this.state, 'mirrorId'), this._onChangeMirrorId, this); + + this.receive(utils.observe(this.state, 'paymentId'), this._updateGatewayDetails, this); + this.receive(utils.observe(this.tx, 'recipient'), this._updateGatewayDetails, this); + + this.receive(utils.observe(this.state, 'paymentId'), this._updateGatewayPermisson, this); + this.receive(utils.observe(this.tx, 'recipient'), this._updateGatewayPermisson, this); + + this.receive(utils.observe(this.tx, 'amount'), this._onChangeAmount, this); + + this.observe('gatewayDetails', this._updateWavesTxObject); + this.receive(utils.observe(this.tx, 'amount'), this._updateWavesTxObject, this); + this.receive(utils.observe(this.tx, 'recipient'), this._updateWavesTxObject, this); + this.receive(utils.observe(this.tx, 'attachment'), this._updateWavesTxObject, this); + + this.observe('mirror', this._onChangeAmountMirror); + this.observe(['gatewayAddressError', 'gatewayDetailsError', 'gatewayWrongAddress'], + this._updateGatewayError); + + this._currentHasCommission(); + this._onChangeBaseAssets(); + this._updateGatewayDetails(); + this._updateGatewayPermisson(); + }; + if (!this.state.moneyHash) { + this.receiveOnce(utils.observe(this.state, 'moneyHash'), onHasMoneyHash); + } else { + onHasMoneyHash(); + } + this.receive(utils.observe(this.state, 'moneyHash'), () => { + this._currentHasCommission(); + this._onChangeBaseAssets(); + this._updateGatewayDetails(); + }); + this._onChangeBaseAssets(); + this._updateWavesTxObject(); + } + + onSignCoinomatStart() { + this.signInProgress = true; + } + + onSignCoinomatEnd() { + this.signInProgress = false; + } + + createTx() { + const toGateway = this.outerSendMode && this.gatewayDetails; + const fee = toGateway ? this.tx.amount.cloneWithTokens(toGateway.gatewayFee) : null; + const attachmentString = this.tx.attachment ? this.tx.attachment.toString() : ''; + const tx = waves.node.transactions.createTransaction({ + ...this.tx, + recipient: toGateway ? this.gatewayDetails.address : this.tx.recipient, + attachment: utils.stringToBytes(toGateway ? this.gatewayDetails.attachment : attachmentString), + amount: toGateway ? this.tx.amount.add(fee) : this.tx.amount + }); + + const signable = ds.signature.getSignatureApi().makeSignable({ + type: tx.type, + data: tx + }); + + return signable; + } + + onSignTx(signable) { + analytics.send({ name: 'Transfer Continue Click', target: 'ui' }); + this.onContinue({ signable }); + } + + fillMax() { + let amount = null; + const moneyHash = utils.groupMoney(this.feeList); + if (moneyHash[this.assetId]) { + amount = this.balance.sub(moneyHash[this.assetId]); + } else { + amount = this.balance; + } + + if (amount.getTokens().lt(0)) { + amount = this.moneyHash[this.assetId].cloneWithTokens('0'); + } + + waves.utils.getRate(this.assetId, this.mirrorId).then(rate => { + this._noCurrentRate = true; + this.mirror = amount.convertTo(this.moneyHash[this.mirrorId].asset, rate); + this.tx.amount = amount; + this._noCurrentRate = false; + $scope.$apply(); + }); + } + + onBlurMirror() { + if (!this.mirror) { + this._fillMirror(); + } + this.focus = ''; + } + + /** + * @param {string} url + * @return {null} + */ + onReadQrCode(url) { + if (!url.includes('https://')) { + this.tx.recipient = url; + $scope.$apply(); + return null; + } + + const routeData = utils.getRouterParams(utils.getUrlForRoute(url)); + + if (!routeData || routeData.name !== 'SEND_ASSET') { + return null; + } + + const result = routeData.data; + + this.tx.recipient = result.recipient; + + // analytics.push('Send', `Send.QrCodeRead.${WavesApp.type}`, + // `Send.QrCodeRead.${WavesApp.type}.Success`); + + if (result) { + + const applyAmount = () => { + if (result.amount) { + this.tx.amount = this.moneyHash[this.assetId].cloneWithTokens(result.amount); + this._fillMirror(); + } + $scope.$apply(); + }; + + result.assetId = result.asset || result.assetId; + + if (result.assetId) { + waves.node.assets.balance(result.assetId).then(({ available }) => { + this.moneyHash[available.asset.id] = available; + + if (this.assetId !== available.asset.id) { + const myAssetId = this.assetId; + this.assetId = available.asset.id; + this.canChooseAsset = true; + // TODO fix (hack for render asset avatar) + this.choosableMoneyList = [this.moneyHash[myAssetId], available]; + } + + applyAmount(); + }, applyAmount); + } else { + applyAmount(); + } + } + } + + /** + * @return {boolean} + */ + isMoneroNotIntegratedAddress() { + const moneroAddressLength = 95; + const assetIsMonero = this.state.assetId === WavesApp.defaultAssets.XMR; + return assetIsMonero && this.tx.recipient.length === moneroAddressLength; + } + + getGatewayDetails() { + this._onChangeAssetId(); + } + + /** + * @private + */ + _updateWavesTxObject() { + const toGateway = this.outerSendMode && this.gatewayDetails; + const fee = toGateway ? this.tx.amount.cloneWithTokens(toGateway.gatewayFee) : null; + const attachmentString = this.tx.attachment ? this.tx.attachment.toString() : ''; + const isWavesAddress = user.isValidAddress(this.tx.recipient); + this.wavesTx = { + ...this.wavesTx, + recipient: toGateway ? this.gatewayDetails.address : isWavesAddress && this.tx.recipient || '', + attachment: utils.stringToBytes(toGateway ? this.gatewayDetails.attachment : attachmentString), + amount: toGateway ? this.tx.amount.add(fee) : this.tx.amount, + assetId: this.assetId + }; + } + + /** + * @private + */ + _validateForm() { + if (this.tx.amount.getTokens().gt(0) || this.tx.recipient) { + this.send.$setDirty(true); + this.send.$setSubmitted(true); + } + } + + /** + * @private + */ + _onChangeBankMode() { + if (this.toBankMode && !this.isLira) { + this.tx.recipient = BANK_RECIPIENT; + this.termsIsPending = true; + } else { + this.tx.recipient = ''; + this.termsIsPending = false; + } + + this._setMinAmount(); + this._updateGatewayPermisson(); + } + + /** + * @private + */ + _setMinAmount() { + if (this.toBankMode && !this.isLira) { + const maxCoinomatAmount = this.balance.cloneWithTokens(50000); + const minCoinomatAmount = this.balance.cloneWithTokens(100); + + this.maxAmount = Money.min(maxCoinomatAmount, this.balance); + this.minAmount = minCoinomatAmount; + } else { + this.minAmount = this.state.moneyHash[this.assetId].cloneWithTokens('0'); + this.maxAmount = this.moneyHash[this.assetId]; + } + + this._validateForm(); + } + + /** + * @private + */ + _onChangeMirrorId() { + if (!this.mirrorId) { + throw new Error('Has no asset id!'); + } + + this._onChangeBaseAssets(); + + if (!this.moneyHash[this.mirrorId]) { + return null; + } + + this.mirror = this.moneyHash[this.mirrorId].cloneWithTokens('0'); + this._onChangeAmount(); + } + + /** + * @private + */ + _onChangeAssetId() { + if (!this.assetId) { + throw new Error('Has no asset id!'); + } + + this._onChangeBaseAssets(); + + if (!this.moneyHash[this.assetId]) { + return null; + } + + this.tx.amount = this.moneyHash[this.assetId].cloneWithTokens('0'); + this.mirror = this.moneyHash[this.mirrorId].cloneWithTokens('0'); + this._updateGatewayDetails(); + this._updateGatewayPermisson(); + } + + /** + * @private + */ + _currentHasCommission() { + if (!this.moneyHash) { + return null; + } + + const details = this.gatewayDetails; + + const check = (feeList) => { + const feeHash = utils.groupMoney(feeList); + const balanceHash = this.moneyHash; + + this.hasComission = Object.keys(feeHash).every((feeAssetId) => { + const fee = feeHash[feeAssetId]; + return balanceHash[fee.asset.id] && balanceHash[fee.asset.id].gte(fee); + }); + }; + + if (details) { + const gatewayFee = this.balance.cloneWithTokens(details.gatewayFee); + this.feeList = [this.tx.fee, gatewayFee]; + check(this.feeList.concat(this.balance.cloneWithTokens(details.minimumAmount))); + } else { + this.feeList = [this.tx.fee]; + check(this.feeList); + } + } + + /** + * @private + */ + _onChangeBaseAssets() { + if (this.assetId === this.mirrorId) { + this.noMirror = true; + } else { + waves.utils.getRate(this.assetId, this.mirrorId).then((rate) => { + this.noMirror = rate.eq(0); + }); + } + } + + /** + * @private + */ + _onChangeAmount() { + if (!this._noCurrentRate && !this.noMirror && this.focus === 'amount') { + this._fillMirror(); + } + + } + + /** + * @private + */ + _onChangeAmountMirror() { + if (!this._noCurrentRate && this.focus === 'mirror') { + this._fillAmount(); + } + } + + /** + * @private + */ + _fillMirror() { + + if (!this.tx.amount) { + this.mirror = null; + setTimeout(() => $scope.$digest(), 0); + return null; + } + + waves.utils.getRate(this.assetId, this.mirrorId).then((rate) => { + this.mirror = this.tx.amount.convertTo(this.moneyHash[this.mirrorId].asset, rate); + $scope.$digest(); + }); + } + + /** + * @private + */ + _fillAmount() { + + if (!this.mirror) { + this.tx.amount = null; + setTimeout(() => $scope.$digest(), 0); + return null; + } + + waves.utils.getRate(this.mirrorId, this.assetId).then((rate) => { + this.tx.amount = this.mirror.convertTo(this.moneyHash[this.assetId].asset, rate); + $scope.$digest(); + }); + } + + /** + * @private + */ + _updateGatewayDetails() { + if (this.toBankMode && !this.isLira) { + this._setMinAmount(); + return; + } + + const outerChain = outerBlockchains[this.assetId]; + const isValidWavesAddress = user.isValidAddress(this.tx.recipient); + + if (this.gatewayDetailsError) { + this.outerSendMode = false; + this.gatewayDetailsError = false; + } + + if (this.gatewayAddressError) { + this.gatewayAddressError = false; + } + + if (this.gatewayWrongAddress) { + this.gatewayWrongAddress = false; + } + + this.outerSendMode = !isValidWavesAddress && outerChain && outerChain.isValidAddress(this.tx.recipient); + + if (this.outerSendMode) { + return gatewayService.getWithdrawDetails(this.balance.asset, this.tx.recipient, this.paymentId) + .then((details) => { + const max = BigNumber.min( + details.maximumAmount.add(details.gatewayFee), + this.moneyHash[this.assetId].getTokens() + ); + + this.gatewayDetails = details; + this.minAmount = this.moneyHash[this.assetId] + .cloneWithTokens(details.minimumAmount.sub('0.00000001')); + this.maxAmount = this.moneyHash[this.assetId].cloneWithTokens(max); + this.maxGatewayAmount = Money.fromTokens(details.maximumAmount, this.balance.asset); + $scope.$apply(); + }, (e) => { + this.gatewayDetails = null; + if (e.message === gatewayService.getAddressErrorMessage(this.balance.asset, + this.tx.recipient, 'errorAddressMessage')) { + this.gatewayAddressError = true; + } else if (e.message === gatewayService.getWrongAddressMessage(this.balance.asset, + this.tx.recipient, 'wrongAddressMessage')) { + this.gatewayWrongAddress = true; + } else { + this.gatewayDetailsError = true; + } + $scope.$apply(); + }); + } else { + this.minAmount = this.state.moneyHash[this.assetId].cloneWithTokens('0'); + this.maxAmount = this.moneyHash[this.assetId]; + this.gatewayDetails = null; + this._validateForm(); + } + return Promise.resolve(); + } + + /** + * @private + */ + _updateGatewayPermisson() { + this.gatewayDetailsError = this.outerSendMode ? !this.isGatewayAccepted : this.gatewayDetailsError; + } + + /** + * @private + */ + _updateGatewayError() { + this.gatewayError = this.gatewayAddressError || this.gatewayDetailsError || this.gatewayWrongAddress; + } + + } + + return new GatewaySend(); + }; + + controller.$inject = [ + 'Base', + '$scope', + 'utils', + 'createPoll', + 'waves', + 'configService', + 'outerBlockchains', + 'user', + 'gatewayService' + ]; + + angular.module('app.ui').component('wGatewaySend', { + bindings: { + state: '<', + onContinue: '&' + }, + templateUrl: 'modules/utils/modals/sendAsset/components/singleSend/gatewaySend/gateway-send.html', + transclude: true, + controller + }); +})(); + +/** + * @typedef {object} ISendTx + * @property {Money} fee + * @property {Money} amount + * @property {string} recipient + * @property {string} attachment + */ diff --git a/src/modules/utils/modals/sendAsset/components/singleSend/gatewaySend/gateway-send.html b/src/modules/utils/modals/sendAsset/components/singleSend/gatewaySend/gateway-send.html new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/modules/utils/modals/sendAsset/components/singleSend/single-send.html b/src/modules/utils/modals/sendAsset/components/singleSend/single-send.html index 4711a9d1ba..4f2a1abbd4 100644 --- a/src/modules/utils/modals/sendAsset/components/singleSend/single-send.html +++ b/src/modules/utils/modals/sendAsset/components/singleSend/single-send.html @@ -1,318 +1,18 @@ -
- + + -
-
-
-
-
-
- -
-
-
-
- - -
-
- -
- - -
- - -
- - - -
- - - - - - - -
-
- -
- -
- -
-
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
- -
-
- -
-
-
-
-
-
- -
-
-
-
-
-
- -
-
-
-
-
-
- -
-
- -
- -
- - - - - - - - - - - - - -
-
- - -
-
- - - -
- - - -
- - -
- - -
- - -
-
-
-
- - - - -
- -
-
- - - - - - - -
- -
- -
- -
- - -
- -
- -
- -
-
-
-
-
- -
- -
-
-
- -
- - - + + + - - - -
-
+ + + diff --git a/src/modules/utils/modals/sendAsset/components/singleSend/wavesSend/WavesSend.js b/src/modules/utils/modals/sendAsset/components/singleSend/wavesSend/WavesSend.js new file mode 100644 index 0000000000..d1f8d2160a --- /dev/null +++ b/src/modules/utils/modals/sendAsset/components/singleSend/wavesSend/WavesSend.js @@ -0,0 +1,668 @@ +(function () { + 'use strict'; + + const FIAT_ASSETS = { + [WavesApp.defaultAssets.USD]: true, + [WavesApp.defaultAssets.EUR]: true, + [WavesApp.defaultAssets.TRY]: true + }; + + const { BigNumber } = require('@waves/bignumber'); + const ds = require('data-service'); + const { SIGN_TYPE } = require('@waves/signature-adapter'); + const analytics = require('@waves/event-sender'); + + const BANK_RECIPIENT = WavesApp.bankRecipient; + const MIN_TOKEN_COUNT = 100; + const MAX_TOKEN_COUNT = 50000; + + /** + * @param {Base} Base + * @param {$rootScope.Scope} $scope + * @param {app.utils} utils + * @param {IPollCreate} createPoll + * @param {ConfigService} configService + * @param {IOuterBlockchains} outerBlockchains + * @param {User} user + * @param {GatewayService} gatewayService + * @param {Waves} waves + */ + const controller = function (Base, + $scope, + utils, + createPoll, + waves, + configService, + outerBlockchains, + user, + gatewayService) { + + class WavesSend extends Base { + + /** + * @return {boolean} + */ + get canSendToBank() { + return (FIAT_ASSETS[this.assetId] && !this.isLira) || false; + } + + /** + * @return {boolean} + */ + get isLira() { + return this.assetId === WavesApp.defaultAssets.TRY; + } + + /** + * @return {ISingleSendTx} + */ + get tx() { + return this.state.singleSend; + } + + /** + * @return {string} + */ + get assetId() { + return this.state.assetId; + } + + set assetId(id) { + this.state.assetId = id; + } + + /** + * @return {string} + */ + get mirrorId() { + return this.state.mirrorId; + } + + /** + * @return {Object} + */ + get moneyHash() { + return this.state.moneyHash; + } + + /** + * @return {Money} + */ + get balance() { + return this.moneyHash[this.assetId]; + } + + /** + * @return {boolean} + */ + get outerSendMode() { + return this.state.outerSendMode; + } + + set outerSendMode(value) { + this.state.outerSendMode = value; + } + + /** + * @return {string} + */ + get paymentId() { + return this.state.paymentId; + } + + set paymentId(value) { + this.state.paymentId = value; + } + + /** + * @return {IGatewayDetails} + */ + get gatewayDetails() { + return this.state.gatewayDetails; + } + + set gatewayDetails(value) { + this.state.gatewayDetails = value; + } + + get isBankPending() { + return this.toBankMode && this.termsIsPending; + } + + get isBankError() { + return this.toBankMode && this.termsLoadError; + } + + get isGatewayAccepted() { + return !configService + .get('PERMISSIONS.CANT_TRANSFER_GATEWAY').includes(this.balance.asset.id); + } + + get isBankAccepted() { + return this.toBankMode ? this.isGatewayAccepted : true; + } + + get isBankPendingOrError() { + return this.isBankError || this.isBankPending; + } + + get minimumAmount() { + return this.gatewayDetails && + this.gatewayDetails.minimumAmount || + this.toBankMode && + new BigNumber(MIN_TOKEN_COUNT); + } + + get maximumAmount() { + return this.maxGatewayAmount || this.toBankMode && this.balance.cloneWithTokens(MAX_TOKEN_COUNT); + } + + /** + * @type {string} + */ + txType = WavesApp.TRANSACTION_TYPES.NODE.TRANSFER; + + /** + * @type {boolean} + */ + get toBankMode() { + return this.state.toBankMode; + } + + set toBankMode(value) { + this.state.toBankMode = value; + } + + /** + * @type {string} + */ + digiLiraUserLink = 'https://www.digilira.com/'; + /** + * @type {Function} + */ + onContinue = null; + /** + * @type {Function} + */ + onChangeMode = null; + /** + * @type {string} + */ + focus = null; + /** + * @type {Money} + */ + mirror = null; + /** + * @type {boolean} + */ + noMirror = false; + /** + * @type {boolean} + */ + hasFee = true; + /** + * @type {Array} + */ + feeList = null; + /** + * @type {Money} + */ + minAmount = null; + /** + * @type {Money} + */ + maxAmount = null; + /** + * @type {ISendState} + */ + state = Object.create(null); + /** + * @type {Money} + */ + maxGatewayAmount = null; + /** + * @type {boolean} + */ + gatewayDetailsError = false; + /** + * @type {boolean} + */ + gatewayAddressError = false; + /** + * @type {boolean} + */ + gatewayWrongAddress = false; + /** + * @type {boolean} + */ + gatewayError = false; + /** + * @type {boolean} + */ + termsIsPending = true; + /** + * @type {boolean} + */ + termsLoadError = false; + /** + * @type {boolean} + */ + signInProgress = false; + /** + * @type {ISingleSendTx} + */ + wavesTx = { + type: SIGN_TYPE.TRANSFER, + amount: null, + attachment: '', + fee: null, + recipient: '', + assetId: '' + }; + + constructor() { + gatewayService.getFiats(); + super(); + } + + $postLink() { + this.receive(utils.observe(this.tx, 'recipient'), this._onUpdateRecipient, this); + const onHasMoneyHash = () => { + // this.receive(utils.observe(this.state, 'toBankMode'), this._onChangeBankMode, this); + // this.observe('gatewayDetails', this._checkFee); + this.receive(utils.observe(this.tx, 'fee'), this._onUpdateFee, this); + this.tx.amount = this.tx.amount || this.moneyHash[this.assetId].cloneWithTokens('0'); + // this._fillMirror(); + + // this.receive(utils.observe(this.state, 'assetId'), this._onChangeAssetId, this); + // this.receive(utils.observe(this.state, 'mirrorId'), this._onChangeMirrorId, this); + + // this.receive(utils.observe(this.state, 'paymentId'), this._updateGatewayDetails, this); + // this.receive(utils.observe(this.tx, 'recipient'), this._updateGatewayDetails, this); + + // this.receive(utils.observe(this.state, 'paymentId'), this._updateGatewayPermisson, this); + // this.receive(utils.observe(this.tx, 'recipient'), this._updateGatewayPermisson, this); + + this.receive(utils.observe(this.tx, 'amount'), this._onChangeAmount, this); + this.observe('mirror', this._onChangeAmountMirror); + + // this.observe('gatewayDetails', this._updateWavesTxObject); + // this.receive(utils.observe(this.tx, 'amount'), this._updateWavesTxObject, this); + // this.receive(utils.observe(this.tx, 'recipient'), this._updateWavesTxObject, this); + // this.receive(utils.observe(this.tx, 'attachment'), this._updateWavesTxObject, this); + // + // this.observe('mirror', this._onChangeAmountMirror); + // this.observe(['gatewayAddressError', 'gatewayDetailsError', 'gatewayWrongAddress'], + // this._updateGatewayError); + + this._onUpdateFee(); + this._setMinAndMaxAmount(); + this._onChangeBaseAssets(); + // this._updateGatewayDetails(); + // this._updateGatewayPermisson(); + }; + + if (!this.state.moneyHash) { + this.receiveOnce(utils.observe(this.state, 'moneyHash'), onHasMoneyHash); + } else { + onHasMoneyHash(); + } + + this.receive(utils.observe(this.state, 'moneyHash'), () => { + this._onUpdateFee(); + this._setMinAndMaxAmount(); + this._onChangeBaseAssets(); + // this._updateGatewayDetails(); + }); + + this._onChangeBaseAssets(); + this._updateWavesTxObject(); + } + + setSendMode(mode) { + this.onChangeMode({ mode }); + } + + onSignCoinomatStart() { + this.signInProgress = true; + } + + onSignCoinomatEnd() { + this.signInProgress = false; + } + + createTx() { + const toGateway = this.outerSendMode && this.gatewayDetails; + const fee = toGateway ? this.tx.amount.cloneWithTokens(toGateway.gatewayFee) : null; + const attachmentString = this.tx.attachment ? this.tx.attachment.toString() : ''; + const tx = waves.node.transactions.createTransaction({ + ...this.tx, + recipient: toGateway ? this.gatewayDetails.address : this.tx.recipient, + attachment: utils.stringToBytes(toGateway ? this.gatewayDetails.attachment : attachmentString), + amount: toGateway ? this.tx.amount.add(fee) : this.tx.amount + }); + + const signable = ds.signature.getSignatureApi().makeSignable({ + type: tx.type, + data: tx + }); + + return signable; + } + + onSignTx(signable) { + analytics.send({ name: 'Transfer Continue Click', target: 'ui' }); + this.onContinue({ signable }); + } + + fillMax() { + let amount = null; + const moneyHash = utils.groupMoney(this.feeList); + if (moneyHash[this.assetId]) { + amount = this.balance.sub(moneyHash[this.assetId]); + } else { + amount = this.balance; + } + + if (amount.getTokens().lt(0)) { + amount = this.moneyHash[this.assetId].cloneWithTokens('0'); + } + + waves.utils.getRate(this.assetId, this.mirrorId).then(rate => { + this.mirror = amount.convertTo(this.moneyHash[this.mirrorId].asset, rate); + this.tx.amount = amount; + $scope.$apply(); + }); + } + + onBlurMirror() { + if (!this.mirror) { + this._fillMirror(); + } + this.focus = ''; + } + + /** + * @param {string} url + * @return {null} + */ + onReadQrCode(url) { + if (!url.includes('https://')) { + this.tx.recipient = url; + $scope.$apply(); + return null; + } + + const routerData = utils.getRouterParams(utils.getUrlForRoute(url)); + + if (!routerData || routerData.name !== 'SEND_ASSET') { + return null; + } + + const result = routerData.data; + + this.tx.recipient = result.recipient; + + if (result) { + + const applyAmount = () => { + if (result.amount) { + this.tx.amount = this.moneyHash[this.assetId].cloneWithTokens(result.amount); + this._fillMirror(); + } + $scope.$apply(); + }; + + result.assetId = result.asset || result.assetId; + + if (result.assetId) { + waves.node.assets.balance(result.assetId).then(({ available }) => { + this.moneyHash[available.asset.id] = available; + + if (this.assetId !== available.asset.id) { + const myAssetId = this.assetId; + this.assetId = available.asset.id; + this.canChooseAsset = true; + // TODO fix (hack for render asset avatar) + this.choosableMoneyList = [this.moneyHash[myAssetId], available]; + } + + applyAmount(); + }, applyAmount); + } else { + applyAmount(); + } + } + } + + /** + * @return {boolean} + */ + isMoneroNotIntegratedAddress() { + const moneroAddressLength = 95; + const assetIsMonero = this.state.assetId === WavesApp.defaultAssets.XMR; + return assetIsMonero && this.tx.recipient.length === moneroAddressLength; + } + + getGatewayDetails() { + this._onChangeAssetId(); + } + + /** + * @private + */ + _updateWavesTxObject() { + const toGateway = this.outerSendMode && this.gatewayDetails; + const fee = toGateway ? this.tx.amount.cloneWithTokens(toGateway.gatewayFee) : null; + const attachmentString = this.tx.attachment ? this.tx.attachment.toString() : ''; + const isWavesAddress = user.isValidAddress(this.tx.recipient); + this.wavesTx = { + ...this.wavesTx, + recipient: toGateway ? this.gatewayDetails.address : isWavesAddress && this.tx.recipient || '', + attachment: utils.stringToBytes(toGateway ? this.gatewayDetails.attachment : attachmentString), + amount: toGateway ? this.tx.amount.add(fee) : this.tx.amount, + assetId: this.assetId + }; + } + + /** + * @private + */ + _validateForm() { + if (this.tx.amount.getTokens().gt(0) || this.tx.recipient) { + this.wavesSend.$setDirty(true); + this.wavesSend.$setSubmitted(true); + } + } + + /** + * @private + */ + _onChangeBankMode() { + if (this.toBankMode && !this.isLira) { + this.tx.recipient = BANK_RECIPIENT; + this.termsIsPending = true; + } else { + this.tx.recipient = ''; + this.termsIsPending = false; + } + + this._updateGatewayPermisson(); + } + + /** + * @private + */ + _onChangeMirrorId() { + if (!this.mirrorId) { + throw new Error('Has no asset id!'); + } + + this._onChangeBaseAssets(); + + if (!this.moneyHash[this.mirrorId]) { + return null; + } + + this.mirror = this.moneyHash[this.mirrorId].cloneWithTokens('0'); + this._onChangeAmount(); + } + + /** + * @private + */ + _onChangeAssetId() { + if (!this.assetId) { + throw new Error('Has no asset id!'); + } + + this._onChangeBaseAssets(); + + if (!this.moneyHash[this.assetId]) { + return null; + } + + this.tx.amount = this.moneyHash[this.assetId].cloneWithTokens('0'); + this.mirror = this.moneyHash[this.mirrorId].cloneWithTokens('0'); + this._updateGatewayPermisson(); + } + + /** + * @private + */ + _onUpdateFee() { + this.feeList = [this.tx.fee]; + + const feeHash = utils.groupMoney(this.feeList); + const balanceHash = this.moneyHash; + + this.hasFee = Object.keys(feeHash).every((feeAssetId) => { + const fee = feeHash[feeAssetId]; + return balanceHash[fee.asset.id] && balanceHash[fee.asset.id].gte(fee); + }); + + } + + /** + * @private + */ + _onChangeBaseAssets() { + if (this.assetId === this.mirrorId) { + this.noMirror = true; + } else { + waves.utils.getRate(this.assetId, this.mirrorId).then((rate) => { + this.noMirror = rate.eq(0); + }); + } + } + + _setMinAndMaxAmount() { + this.minAmount = this.state.moneyHash[this.state.assetId].cloneWithTokens('0'); + this.maxAmount = this.moneyHash[this.assetId]; + } + + /** + * @private + */ + _onChangeAmount() { + if (!this.noMirror && this.focus === 'amount') { + this._fillMirror(); + } + + } + + /** + * @private + */ + _onChangeAmountMirror() { + if (this.focus === 'mirror') { + this._fillAmount(); + } + } + + /** + * @private + */ + _fillMirror() { + if (!this.tx.amount) { + this.mirror = null; + return; + } + + waves.utils.getRate(this.assetId, this.mirrorId).then((rate) => { + this.mirror = this.tx.amount.convertTo(this.moneyHash[this.mirrorId].asset, rate); + }); + } + + /** + * @private + */ + _fillAmount() { + if (!this.mirror) { + this.tx.amount = null; + return null; + } + + waves.utils.getRate(this.mirrorId, this.assetId).then((rate) => { + this.tx.amount = this.mirror.convertTo(this.moneyHash[this.assetId].asset, rate); + }); + } + + /** + * @private + */ + _onUpdateRecipient() { + this._validateForm(); + } + + /** + * @private + */ + _updateGatewayPermisson() { + this.gatewayDetailsError = this.outerSendMode ? !this.isGatewayAccepted : this.gatewayDetailsError; + } + + /** + * @private + */ + _updateGatewayError() { + this.gatewayError = this.gatewayAddressError || this.gatewayDetailsError || this.gatewayWrongAddress; + } + + } + + return new WavesSend(); + }; + + controller.$inject = [ + 'Base', + '$scope', + 'utils', + 'createPoll', + 'waves', + 'configService', + 'outerBlockchains', + 'user', + 'gatewayService' + ]; + + angular.module('app.ui').component('wWavesSend', { + bindings: { + state: '<', + onContinue: '&', + onChangeMode: '&' + }, + templateUrl: 'modules/utils/modals/sendAsset/components/singleSend/wavesSend/waves-send.html', + transclude: true, + controller + }); +})(); + +/** + * @typedef {object} ISendTx + * @property {Money} fee + * @property {Money} amount + * @property {string} recipient + * @property {string} attachment + */ diff --git a/src/modules/utils/modals/sendAsset/components/singleSend/wavesSend/waves-send.html b/src/modules/utils/modals/sendAsset/components/singleSend/wavesSend/waves-send.html new file mode 100644 index 0000000000..880a85252a --- /dev/null +++ b/src/modules/utils/modals/sendAsset/components/singleSend/wavesSend/waves-send.html @@ -0,0 +1,128 @@ +
+ + + +
+
+
+
+ +
+
+ + +
+ + + +
+ + + + + + + +
+
+ + +
+
+ + + +
+ + + +
+ + +
+ +
+
+ + + + + + + + +
+ +
+ + +
+ +
+ +
+ +
+ + + +
+
From f21b4c5a1a43645ec84ed09dfc4b3352dacd15cf Mon Sep 17 00:00:00 2001 From: okanishcheva Date: Tue, 20 Aug 2019 18:46:21 +0300 Subject: [PATCH 02/18] DEXW-1239: save --- .../components/singleSend/SingleSend.js | 12 +- .../singleSend/gatewaySend/GatewaySend.js | 671 ++++++------------ .../singleSend/gatewaySend/gateway-send.html | 184 +++++ .../components/singleSend/single-send.html | 7 +- .../singleSend/wavesSend/WavesSend.js | 305 ++------ .../singleSend/wavesSend/waves-send.html | 23 +- 6 files changed, 464 insertions(+), 738 deletions(-) diff --git a/src/modules/utils/modals/sendAsset/components/singleSend/SingleSend.js b/src/modules/utils/modals/sendAsset/components/singleSend/SingleSend.js index a1a2d3e110..d59babc41b 100644 --- a/src/modules/utils/modals/sendAsset/components/singleSend/SingleSend.js +++ b/src/modules/utils/modals/sendAsset/components/singleSend/SingleSend.js @@ -10,14 +10,14 @@ */ sendMode = 'waves'; - constructor() { - this.test = 0; - } - onChangeMode(mode) { this.sendMode = mode; } + onSign(signable) { + this.onContinue({ signable }); + } + } return new SingleSend(); @@ -35,7 +35,3 @@ controller }); })(); - -/** - * @typedef {string} ISendMode = waves | bank | gateway - */ diff --git a/src/modules/utils/modals/sendAsset/components/singleSend/gatewaySend/GatewaySend.js b/src/modules/utils/modals/sendAsset/components/singleSend/gatewaySend/GatewaySend.js index b08d2ee1e8..ea7f286067 100644 --- a/src/modules/utils/modals/sendAsset/components/singleSend/gatewaySend/GatewaySend.js +++ b/src/modules/utils/modals/sendAsset/components/singleSend/gatewaySend/GatewaySend.js @@ -1,59 +1,23 @@ (function () { 'use strict'; - const FIAT_ASSETS = { - [WavesApp.defaultAssets.USD]: true, - [WavesApp.defaultAssets.EUR]: true, - [WavesApp.defaultAssets.TRY]: true - }; - + const { SIGN_TYPE } = require('@waves/signature-adapter'); const { Money } = require('@waves/data-entities'); const { BigNumber } = require('@waves/bignumber'); - const ds = require('data-service'); - const { SIGN_TYPE } = require('@waves/signature-adapter'); - const analytics = require('@waves/event-sender'); - - const BANK_RECIPIENT = WavesApp.bankRecipient; - const MIN_TOKEN_COUNT = 100; - const MAX_TOKEN_COUNT = 50000; /** * @param {Base} Base * @param {$rootScope.Scope} $scope * @param {app.utils} utils - * @param {IPollCreate} createPoll - * @param {ConfigService} configService - * @param {IOuterBlockchains} outerBlockchains * @param {User} user - * @param {GatewayService} gatewayService * @param {Waves} waves + * @param {IOuterBlockchains} outerBlockchains + * @param {GatewayService} gatewayService */ - const controller = function (Base, - $scope, - utils, - createPoll, - waves, - configService, - outerBlockchains, - user, - gatewayService) { + const controller = function (Base, $scope, utils, user, waves, outerBlockchains, gatewayService) { class GatewaySend extends Base { - /** - * @return {boolean} - */ - get hasSendToBank() { - return FIAT_ASSETS[this.assetId] || false; - } - - /** - * @return {boolean} - */ - get isLira() { - return this.assetId === WavesApp.defaultAssets.TRY; - } - /** * @return {ISingleSendTx} */ @@ -68,10 +32,6 @@ return this.state.assetId; } - set assetId(id) { - this.state.assetId = id; - } - /** * @return {string} */ @@ -86,13 +46,6 @@ return this.state.moneyHash; } - /** - * @return {Object.} - */ - get feeHash() { - return utils.groupMoney(this.feeList || []); - } - /** * @return {Money} */ @@ -100,17 +53,6 @@ return this.moneyHash[this.assetId]; } - /** - * @return {boolean} - */ - get outerSendMode() { - return this.state.outerSendMode; - } - - set outerSendMode(value) { - this.state.outerSendMode = value; - } - /** * @return {string} */ @@ -118,117 +60,33 @@ return this.state.paymentId; } - set paymentId(value) { - this.state.paymentId = value; - } - - /** - * @return {IGatewayDetails} - */ - get gatewayDetails() { - return this.state.gatewayDetails; - } - - set gatewayDetails(value) { - this.state.gatewayDetails = value; - } - - get isBankPending() { - return this.toBankMode && this.termsIsPending; - } - - get isBankError() { - return this.toBankMode && this.termsLoadError; - } - - get isGatewayAccepted() { - return !configService - .get('PERMISSIONS.CANT_TRANSFER_GATEWAY').includes(this.balance.asset.id); - } - - get isBankAccepted() { - return this.toBankMode ? this.isGatewayAccepted : true; - } - - get isBankPendingOrError() { - return this.isBankError || this.isBankPending; - } - - get hasOuterError() { - return this.outerSendMode && this.gatewayError || this.isBankError; - } - - get minimumAmount() { - return this.gatewayDetails && - this.gatewayDetails.minimumAmount || - this.toBankMode && - new BigNumber(MIN_TOKEN_COUNT); - } - - get maximumAmount() { - return this.maxGatewayAmount || this.toBankMode && this.balance.cloneWithTokens(MAX_TOKEN_COUNT); - } - - /** - * @type {string} - */ - txType = WavesApp.TRANSACTION_TYPES.NODE.TRANSFER; - - /** - * @type {boolean} - */ - get toBankMode() { - return this.state.toBankMode; - } - - set toBankMode(value) { - this.state.toBankMode = value; - } - - /** - * @type {string} - */ - digiLiraUserLink = 'https://www.digilira.com/'; /** * @type {Function} */ - onContinue = null; + onSign = null; /** - * @type {string} + * @type {Function} */ - focus = null; + onChangeMode = null; /** - * @type {Money} + * @type {ISingleSendTx} */ - mirror = null; + wavesTx = { + type: SIGN_TYPE.TRANSFER, + amount: null, + attachment: '', + fee: null, + recipient: '', + assetId: '' + }; /** - * @type {boolean} + * @type {IGatewayDetails} */ - noMirror = false; + gatewayDetails = null; /** * @type {boolean} */ - hasComission = true; - /** - * @type {Array} - */ - feeList = null; - /** - * @type {Money} - */ - minAmount = null; - /** - * @type {Money} - */ - maxAmount = null; - /** - * @type {ISendState} - */ - state = Object.create(null); - /** - * @type {Money} - */ - maxGatewayAmount = null; + gatewayError = false; /** * @type {boolean} */ @@ -242,152 +100,75 @@ */ gatewayWrongAddress = false; /** - * @type {boolean} + * @type {Money | null} */ - gatewayError = false; + mirror = null; /** - * @type {boolean} + * @type {string} */ - termsIsPending = true; + focus = ''; /** * @type {boolean} */ - termsLoadError = false; + hasFee = true; /** - * @type {boolean} + * @type {Array} */ - signInProgress = false; + feeList = []; /** - * @type {ISingleSendTx} + * @type {Money} */ - wavesTx = { - type: SIGN_TYPE.TRANSFER, - amount: null, - attachment: '', - fee: null, - recipient: '', - assetId: '' - }; + minAmount = null; /** - * @type {boolean} - * @private + * @type {Money} */ - _noCurrentRate = false; - - constructor() { - super(); - - $scope.WavesApp = WavesApp; - } + maxAmount = null; + /** + * @type {Money} + */ + maxGatewayAmount = null; $postLink() { - this.receive(utils.observe(this.tx, 'fee'), this._currentHasCommission, this); + this.receive(utils.observe(this.tx, 'recipient'), this._onUpdateRecipient, this); + this.observe(['gatewayAddressError', 'gatewayDetailsError', 'gatewayWrongAddress'], + this._updateGatewayError); + const onHasMoneyHash = () => { - this.receive(utils.observe(this.state, 'toBankMode'), this._onChangeBankMode, this); - this.observe('gatewayDetails', this._currentHasCommission); - this.minAmount = this.state.moneyHash[this.state.assetId].cloneWithTokens('0'); - this.tx.amount = this.tx.amount || this.moneyHash[this.assetId].cloneWithTokens('0'); - this._fillMirror(); + this.receive(utils.observe(this.tx, 'fee'), this._onChangeFee, this); + this.receive(utils.observe(this.tx, 'amount'), this._onChangeAmount, this); this.receive(utils.observe(this.state, 'assetId'), this._onChangeAssetId, this); this.receive(utils.observe(this.state, 'mirrorId'), this._onChangeMirrorId, this); - this.receive(utils.observe(this.state, 'paymentId'), this._updateGatewayDetails, this); - this.receive(utils.observe(this.tx, 'recipient'), this._updateGatewayDetails, this); - - this.receive(utils.observe(this.state, 'paymentId'), this._updateGatewayPermisson, this); - this.receive(utils.observe(this.tx, 'recipient'), this._updateGatewayPermisson, this); - - this.receive(utils.observe(this.tx, 'amount'), this._onChangeAmount, this); + this.observe('mirror', this._onChangeAmountMirror); + this.observe('gatewayDetails', this._onChangeGatewayDetails); - this.observe('gatewayDetails', this._updateWavesTxObject); this.receive(utils.observe(this.tx, 'amount'), this._updateWavesTxObject, this); this.receive(utils.observe(this.tx, 'recipient'), this._updateWavesTxObject, this); - this.receive(utils.observe(this.tx, 'attachment'), this._updateWavesTxObject, this); - this.observe('mirror', this._onChangeAmountMirror); - this.observe(['gatewayAddressError', 'gatewayDetailsError', 'gatewayWrongAddress'], - this._updateGatewayError); - - this._currentHasCommission(); - this._onChangeBaseAssets(); - this._updateGatewayDetails(); - this._updateGatewayPermisson(); + this._onChangeFee(); + this._fillMirror(); }; + if (!this.state.moneyHash) { this.receiveOnce(utils.observe(this.state, 'moneyHash'), onHasMoneyHash); } else { onHasMoneyHash(); } - this.receive(utils.observe(this.state, 'moneyHash'), () => { - this._currentHasCommission(); - this._onChangeBaseAssets(); - this._updateGatewayDetails(); - }); - this._onChangeBaseAssets(); - this._updateWavesTxObject(); - } - - onSignCoinomatStart() { - this.signInProgress = true; - } - - onSignCoinomatEnd() { - this.signInProgress = false; - } - createTx() { - const toGateway = this.outerSendMode && this.gatewayDetails; - const fee = toGateway ? this.tx.amount.cloneWithTokens(toGateway.gatewayFee) : null; - const attachmentString = this.tx.attachment ? this.tx.attachment.toString() : ''; - const tx = waves.node.transactions.createTransaction({ - ...this.tx, - recipient: toGateway ? this.gatewayDetails.address : this.tx.recipient, - attachment: utils.stringToBytes(toGateway ? this.gatewayDetails.attachment : attachmentString), - amount: toGateway ? this.tx.amount.add(fee) : this.tx.amount - }); - - const signable = ds.signature.getSignatureApi().makeSignable({ - type: tx.type, - data: tx + this.receive(utils.observe(this.state, 'moneyHash'), () => { + this._onChangeFee(); }); - return signable; - } - - onSignTx(signable) { - analytics.send({ name: 'Transfer Continue Click', target: 'ui' }); - this.onContinue({ signable }); + this._updateGatewayDetails() + .then(() => { + this._validateForm(); + }); } - fillMax() { - let amount = null; - const moneyHash = utils.groupMoney(this.feeList); - if (moneyHash[this.assetId]) { - amount = this.balance.sub(moneyHash[this.assetId]); - } else { - amount = this.balance; - } - - if (amount.getTokens().lt(0)) { - amount = this.moneyHash[this.assetId].cloneWithTokens('0'); - } - - waves.utils.getRate(this.assetId, this.mirrorId).then(rate => { - this._noCurrentRate = true; - this.mirror = amount.convertTo(this.moneyHash[this.mirrorId].asset, rate); - this.tx.amount = amount; - this._noCurrentRate = false; - $scope.$apply(); - }); - } - - onBlurMirror() { - if (!this.mirror) { - this._fillMirror(); - } - this.focus = ''; + setSendMode(mode) { + this.onChangeMode({ mode }); } /** @@ -401,19 +182,16 @@ return null; } - const routeData = utils.getRouterParams(utils.getUrlForRoute(url)); + const routerData = utils.getRouterParams(utils.getUrlForRoute(url)); - if (!routeData || routeData.name !== 'SEND_ASSET') { + if (!routerData || routerData.name !== 'SEND_ASSET') { return null; } - const result = routeData.data; + const result = routerData.data; this.tx.recipient = result.recipient; - // analytics.push('Send', `Send.QrCodeRead.${WavesApp.type}`, - // `Send.QrCodeRead.${WavesApp.type}.Success`); - if (result) { const applyAmount = () => { @@ -451,73 +229,131 @@ */ isMoneroNotIntegratedAddress() { const moneroAddressLength = 95; - const assetIsMonero = this.state.assetId === WavesApp.defaultAssets.XMR; + const assetIsMonero = this.assetId === WavesApp.defaultAssets.XMR; return assetIsMonero && this.tx.recipient.length === moneroAddressLength; } - getGatewayDetails() { - this._onChangeAssetId(); + fillMax() { + let amount = null; + const moneyHash = utils.groupMoney(this.feeList); + if (moneyHash[this.assetId]) { + amount = this.balance.sub(moneyHash[this.assetId]); + } else { + amount = this.balance; + } + + if (amount.getTokens().lt(0)) { + amount = this.balance.cloneWithTokens('0'); + } + + waves.utils.getRate(this.assetId, this.mirrorId).then(rate => { + this.mirror = amount.convertTo(this.moneyHash[this.mirrorId].asset, rate); + this.tx.amount = amount; + $scope.$apply(); + }); + } + + onBlurMirror() { + if (!this.mirror) { + this._fillMirror(); + } + this.focus = ''; + } + + createTx() { + const fee = this.tx.amount.cloneWithTokens(this.gatewayDetails.gatewayFee); + const tx = waves.node.transactions.createTransaction({ + ...this.tx, + recipient: this.gatewayDetails.address, + attachment: utils.stringToBytes(this.gatewayDetails.attachment), + amount: this.tx.amount.add(fee) + }); + + const signable = ds.signature.getSignatureApi().makeSignable({ + type: tx.type, + data: tx + }); + + return signable; + } + + onSignTx(signable) { + analytics.send({ name: 'Transfer Continue Click', target: 'ui' }); + this.onSign({ signable }); } /** * @private */ - _updateWavesTxObject() { - const toGateway = this.outerSendMode && this.gatewayDetails; - const fee = toGateway ? this.tx.amount.cloneWithTokens(toGateway.gatewayFee) : null; - const attachmentString = this.tx.attachment ? this.tx.attachment.toString() : ''; - const isWavesAddress = user.isValidAddress(this.tx.recipient); - this.wavesTx = { - ...this.wavesTx, - recipient: toGateway ? this.gatewayDetails.address : isWavesAddress && this.tx.recipient || '', - attachment: utils.stringToBytes(toGateway ? this.gatewayDetails.attachment : attachmentString), - amount: toGateway ? this.tx.amount.add(fee) : this.tx.amount, - assetId: this.assetId - }; + _updateGatewayDetails() { + if (this.gatewayError) { + this.gatewayError = false; + } + if (this.gatewayDetailsError) { + this.outerSendMode = false; + this.gatewayDetailsError = false; + } + + if (this.gatewayAddressError) { + this.gatewayAddressError = false; + } + + if (this.gatewayWrongAddress) { + this.gatewayWrongAddress = false; + } + + return gatewayService.getWithdrawDetails(this.balance.asset, this.tx.recipient, this.paymentId) + .then(details => { + const max = BigNumber.min( + details.maximumAmount.add(details.gatewayFee), + this.balance.getTokens() + ); + + this.gatewayDetails = details; + this.minAmount = this.balance.cloneWithTokens(details.minimumAmount); + this.maxAmount = this.balance.cloneWithTokens(max); + this.maxGatewayAmount = Money.fromTokens(details.maximumAmount, this.balance.asset); + $scope.$apply(); + }, e => { + this.gatewayDetails = null; + if (e.message === gatewayService.getAddressErrorMessage(this.balance.asset, + this.tx.recipient, 'errorAddressMessage')) { + this.gatewayAddressError = true; + } else if (e.message === gatewayService.getWrongAddressMessage(this.balance.asset, + this.tx.recipient, 'wrongAddressMessage')) { + this.gatewayWrongAddress = true; + } else { + this.gatewayDetailsError = true; + } + $scope.$apply(); + }); } /** * @private */ - _validateForm() { - if (this.tx.amount.getTokens().gt(0) || this.tx.recipient) { - this.send.$setDirty(true); - this.send.$setSubmitted(true); - } + _onUpdateRecipient() { + this._checkOuterBlockchains(); } /** * @private */ - _onChangeBankMode() { - if (this.toBankMode && !this.isLira) { - this.tx.recipient = BANK_RECIPIENT; - this.termsIsPending = true; - } else { - this.tx.recipient = ''; - this.termsIsPending = false; + _checkOuterBlockchains() { + const outerChain = outerBlockchains[this.assetId]; + const isValidWavesAddress = user.isValidAddress(this.tx.recipient); + const gatewayAddress = !isValidWavesAddress && + outerChain && outerChain.isValidAddress(this.tx.recipient); + if (!gatewayAddress) { + this.setSendMode('waves'); } - - this._setMinAmount(); - this._updateGatewayPermisson(); } /** * @private */ - _setMinAmount() { - if (this.toBankMode && !this.isLira) { - const maxCoinomatAmount = this.balance.cloneWithTokens(50000); - const minCoinomatAmount = this.balance.cloneWithTokens(100); - - this.maxAmount = Money.min(maxCoinomatAmount, this.balance); - this.minAmount = minCoinomatAmount; - } else { - this.minAmount = this.state.moneyHash[this.assetId].cloneWithTokens('0'); - this.maxAmount = this.moneyHash[this.assetId]; - } - - this._validateForm(); + _updateGatewayError() { + this.gatewayError = this.gatewayAddressError || this.gatewayDetailsError || this.gatewayWrongAddress; } /** @@ -528,13 +364,11 @@ throw new Error('Has no asset id!'); } - this._onChangeBaseAssets(); - if (!this.moneyHash[this.mirrorId]) { return null; } - this.mirror = this.moneyHash[this.mirrorId].cloneWithTokens('0'); + this.mirror = this.balance.cloneWithTokens('0'); this._onChangeAmount(); } @@ -546,94 +380,34 @@ throw new Error('Has no asset id!'); } - this._onChangeBaseAssets(); - - if (!this.moneyHash[this.assetId]) { + if (!this.balance) { return null; } - this.tx.amount = this.moneyHash[this.assetId].cloneWithTokens('0'); + this.tx.amount = this.balance.cloneWithTokens('0'); this.mirror = this.moneyHash[this.mirrorId].cloneWithTokens('0'); - this._updateGatewayDetails(); - this._updateGatewayPermisson(); - } - - /** - * @private - */ - _currentHasCommission() { - if (!this.moneyHash) { - return null; - } - - const details = this.gatewayDetails; - - const check = (feeList) => { - const feeHash = utils.groupMoney(feeList); - const balanceHash = this.moneyHash; - - this.hasComission = Object.keys(feeHash).every((feeAssetId) => { - const fee = feeHash[feeAssetId]; - return balanceHash[fee.asset.id] && balanceHash[fee.asset.id].gte(fee); - }); - }; - - if (details) { - const gatewayFee = this.balance.cloneWithTokens(details.gatewayFee); - this.feeList = [this.tx.fee, gatewayFee]; - check(this.feeList.concat(this.balance.cloneWithTokens(details.minimumAmount))); - } else { - this.feeList = [this.tx.fee]; - check(this.feeList); - } - } - - /** - * @private - */ - _onChangeBaseAssets() { - if (this.assetId === this.mirrorId) { - this.noMirror = true; - } else { - waves.utils.getRate(this.assetId, this.mirrorId).then((rate) => { - this.noMirror = rate.eq(0); - }); - } } /** * @private */ _onChangeAmount() { - if (!this._noCurrentRate && !this.noMirror && this.focus === 'amount') { + if (this.focus === 'amount') { this._fillMirror(); } - - } - - /** - * @private - */ - _onChangeAmountMirror() { - if (!this._noCurrentRate && this.focus === 'mirror') { - this._fillAmount(); - } } /** * @private */ _fillMirror() { - if (!this.tx.amount) { this.mirror = null; - setTimeout(() => $scope.$digest(), 0); - return null; + return; } - waves.utils.getRate(this.assetId, this.mirrorId).then((rate) => { + waves.utils.getRate(this.assetId, this.mirrorId).then(rate => { this.mirror = this.tx.amount.convertTo(this.moneyHash[this.mirrorId].asset, rate); - $scope.$digest(); }); } @@ -641,94 +415,80 @@ * @private */ _fillAmount() { - if (!this.mirror) { this.tx.amount = null; - setTimeout(() => $scope.$digest(), 0); return null; } - waves.utils.getRate(this.mirrorId, this.assetId).then((rate) => { + waves.utils.getRate(this.mirrorId, this.assetId).then(rate => { this.tx.amount = this.mirror.convertTo(this.moneyHash[this.assetId].asset, rate); - $scope.$digest(); }); } /** * @private */ - _updateGatewayDetails() { - if (this.toBankMode && !this.isLira) { - this._setMinAmount(); - return; + _onChangeAmountMirror() { + if (this.focus === 'mirror') { + this._fillAmount(); } + } - const outerChain = outerBlockchains[this.assetId]; - const isValidWavesAddress = user.isValidAddress(this.tx.recipient); - - if (this.gatewayDetailsError) { - this.outerSendMode = false; - this.gatewayDetailsError = false; - } + /** + * @private + */ + _onChangeFee() { + const details = this.gatewayDetails; - if (this.gatewayAddressError) { - this.gatewayAddressError = false; - } + const check = (feeList) => { + const feeHash = utils.groupMoney(feeList); + const balanceHash = this.moneyHash; - if (this.gatewayWrongAddress) { - this.gatewayWrongAddress = false; - } + this.hasFee = Object.keys(feeHash).every((feeAssetId) => { + const fee = feeHash[feeAssetId]; + return balanceHash[fee.asset.id] && balanceHash[fee.asset.id].gte(fee); + }); + }; - this.outerSendMode = !isValidWavesAddress && outerChain && outerChain.isValidAddress(this.tx.recipient); - - if (this.outerSendMode) { - return gatewayService.getWithdrawDetails(this.balance.asset, this.tx.recipient, this.paymentId) - .then((details) => { - const max = BigNumber.min( - details.maximumAmount.add(details.gatewayFee), - this.moneyHash[this.assetId].getTokens() - ); - - this.gatewayDetails = details; - this.minAmount = this.moneyHash[this.assetId] - .cloneWithTokens(details.minimumAmount.sub('0.00000001')); - this.maxAmount = this.moneyHash[this.assetId].cloneWithTokens(max); - this.maxGatewayAmount = Money.fromTokens(details.maximumAmount, this.balance.asset); - $scope.$apply(); - }, (e) => { - this.gatewayDetails = null; - if (e.message === gatewayService.getAddressErrorMessage(this.balance.asset, - this.tx.recipient, 'errorAddressMessage')) { - this.gatewayAddressError = true; - } else if (e.message === gatewayService.getWrongAddressMessage(this.balance.asset, - this.tx.recipient, 'wrongAddressMessage')) { - this.gatewayWrongAddress = true; - } else { - this.gatewayDetailsError = true; - } - $scope.$apply(); - }); + if (details) { + const gatewayFee = this.balance.cloneWithTokens(details.gatewayFee); + this.feeList = [this.tx.fee, gatewayFee]; + check(this.feeList.concat(this.balance.cloneWithTokens(details.minimumAmount))); } else { - this.minAmount = this.state.moneyHash[this.assetId].cloneWithTokens('0'); - this.maxAmount = this.moneyHash[this.assetId]; - this.gatewayDetails = null; - this._validateForm(); + this.feeList = [this.tx.fee]; + check(this.feeList); } - return Promise.resolve(); } /** * @private */ - _updateGatewayPermisson() { - this.gatewayDetailsError = this.outerSendMode ? !this.isGatewayAccepted : this.gatewayDetailsError; + _updateWavesTxObject() { + const fee = this.tx.amount ? this.tx.amount.cloneWithTokens(this.gatewayDetails.gatewayFee) : null; + this.wavesTx = { + ...this.wavesTx, + recipient: this.gatewayDetails.address, + attachment: utils.stringToBytes(this.gatewayDetails.attachment), + amount: this.tx.amount ? this.tx.amount.add(fee) : null, + assetId: this.assetId + }; } /** * @private */ - _updateGatewayError() { - this.gatewayError = this.gatewayAddressError || this.gatewayDetailsError || this.gatewayWrongAddress; + _onChangeGatewayDetails() { + this._updateWavesTxObject(); + this._onChangeFee(); + } + + /** + * @private + */ + _validateForm() { + if (this.tx.amount.getTokens().gt(0)) { + this.gatewaySend.amount.$setTouched(true); + } } } @@ -740,29 +500,20 @@ 'Base', '$scope', 'utils', - 'createPoll', + 'user', 'waves', - 'configService', 'outerBlockchains', - 'user', 'gatewayService' ]; angular.module('app.ui').component('wGatewaySend', { bindings: { state: '<', - onContinue: '&' + onSign: '&', + onChangeMode: '&' }, templateUrl: 'modules/utils/modals/sendAsset/components/singleSend/gatewaySend/gateway-send.html', transclude: true, controller }); })(); - -/** - * @typedef {object} ISendTx - * @property {Money} fee - * @property {Money} amount - * @property {string} recipient - * @property {string} attachment - */ diff --git a/src/modules/utils/modals/sendAsset/components/singleSend/gatewaySend/gateway-send.html b/src/modules/utils/modals/sendAsset/components/singleSend/gatewaySend/gateway-send.html index e69de29bb2..95ec37528c 100644 --- a/src/modules/utils/modals/sendAsset/components/singleSend/gatewaySend/gateway-send.html +++ b/src/modules/utils/modals/sendAsset/components/singleSend/gatewaySend/gateway-send.html @@ -0,0 +1,184 @@ +
+ + + +
+ +
+
+
+ + +
+ + + +
+
+
+ +
+
+
+
+
+ +
+ +
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+ +
+ +
+ + + + + + + + + + + + + +
+
+ + +
+
+ + + +
+ + + +
+ + +
+ +
+ +
+ +
+ + +
+ +
+ + + +
+ +
diff --git a/src/modules/utils/modals/sendAsset/components/singleSend/single-send.html b/src/modules/utils/modals/sendAsset/components/singleSend/single-send.html index 4f2a1abbd4..1f8be38dc0 100644 --- a/src/modules/utils/modals/sendAsset/components/singleSend/single-send.html +++ b/src/modules/utils/modals/sendAsset/components/singleSend/single-send.html @@ -1,18 +1,19 @@ + state="$ctrl.state" + on-sign="$ctrl.onSign(signable)"> diff --git a/src/modules/utils/modals/sendAsset/components/singleSend/wavesSend/WavesSend.js b/src/modules/utils/modals/sendAsset/components/singleSend/wavesSend/WavesSend.js index d1f8d2160a..3cbde3d414 100644 --- a/src/modules/utils/modals/sendAsset/components/singleSend/wavesSend/WavesSend.js +++ b/src/modules/utils/modals/sendAsset/components/singleSend/wavesSend/WavesSend.js @@ -7,35 +7,24 @@ [WavesApp.defaultAssets.TRY]: true }; - const { BigNumber } = require('@waves/bignumber'); const ds = require('data-service'); const { SIGN_TYPE } = require('@waves/signature-adapter'); const analytics = require('@waves/event-sender'); - const BANK_RECIPIENT = WavesApp.bankRecipient; - const MIN_TOKEN_COUNT = 100; - const MAX_TOKEN_COUNT = 50000; - /** * @param {Base} Base * @param {$rootScope.Scope} $scope * @param {app.utils} utils - * @param {IPollCreate} createPoll - * @param {ConfigService} configService - * @param {IOuterBlockchains} outerBlockchains * @param {User} user - * @param {GatewayService} gatewayService * @param {Waves} waves + * @param {IOuterBlockchains} outerBlockchains */ const controller = function (Base, $scope, utils, - createPoll, waves, - configService, - outerBlockchains, user, - gatewayService) { + outerBlockchains) { class WavesSend extends Base { @@ -67,10 +56,6 @@ return this.state.assetId; } - set assetId(id) { - this.state.assetId = id; - } - /** * @return {string} */ @@ -92,95 +77,10 @@ return this.moneyHash[this.assetId]; } - /** - * @return {boolean} - */ - get outerSendMode() { - return this.state.outerSendMode; - } - - set outerSendMode(value) { - this.state.outerSendMode = value; - } - - /** - * @return {string} - */ - get paymentId() { - return this.state.paymentId; - } - - set paymentId(value) { - this.state.paymentId = value; - } - - /** - * @return {IGatewayDetails} - */ - get gatewayDetails() { - return this.state.gatewayDetails; - } - - set gatewayDetails(value) { - this.state.gatewayDetails = value; - } - - get isBankPending() { - return this.toBankMode && this.termsIsPending; - } - - get isBankError() { - return this.toBankMode && this.termsLoadError; - } - - get isGatewayAccepted() { - return !configService - .get('PERMISSIONS.CANT_TRANSFER_GATEWAY').includes(this.balance.asset.id); - } - - get isBankAccepted() { - return this.toBankMode ? this.isGatewayAccepted : true; - } - - get isBankPendingOrError() { - return this.isBankError || this.isBankPending; - } - - get minimumAmount() { - return this.gatewayDetails && - this.gatewayDetails.minimumAmount || - this.toBankMode && - new BigNumber(MIN_TOKEN_COUNT); - } - - get maximumAmount() { - return this.maxGatewayAmount || this.toBankMode && this.balance.cloneWithTokens(MAX_TOKEN_COUNT); - } - - /** - * @type {string} - */ - txType = WavesApp.TRANSACTION_TYPES.NODE.TRANSFER; - - /** - * @type {boolean} - */ - get toBankMode() { - return this.state.toBankMode; - } - - set toBankMode(value) { - this.state.toBankMode = value; - } - - /** - * @type {string} - */ - digiLiraUserLink = 'https://www.digilira.com/'; /** * @type {Function} */ - onContinue = null; + onSign = null; /** * @type {Function} */ @@ -188,9 +88,9 @@ /** * @type {string} */ - focus = null; + focus = ''; /** - * @type {Money} + * @type {Money | null} */ mirror = null; /** @@ -204,51 +104,15 @@ /** * @type {Array} */ - feeList = null; + feeList = []; /** - * @type {Money} + * @type {Money | null} */ minAmount = null; /** * @type {Money} */ maxAmount = null; - /** - * @type {ISendState} - */ - state = Object.create(null); - /** - * @type {Money} - */ - maxGatewayAmount = null; - /** - * @type {boolean} - */ - gatewayDetailsError = false; - /** - * @type {boolean} - */ - gatewayAddressError = false; - /** - * @type {boolean} - */ - gatewayWrongAddress = false; - /** - * @type {boolean} - */ - gatewayError = false; - /** - * @type {boolean} - */ - termsIsPending = true; - /** - * @type {boolean} - */ - termsLoadError = false; - /** - * @type {boolean} - */ - signInProgress = false; /** * @type {ISingleSendTx} */ @@ -261,46 +125,29 @@ assetId: '' }; - constructor() { - gatewayService.getFiats(); - super(); - } - $postLink() { this.receive(utils.observe(this.tx, 'recipient'), this._onUpdateRecipient, this); - const onHasMoneyHash = () => { - // this.receive(utils.observe(this.state, 'toBankMode'), this._onChangeBankMode, this); - // this.observe('gatewayDetails', this._checkFee); - this.receive(utils.observe(this.tx, 'fee'), this._onUpdateFee, this); - this.tx.amount = this.tx.amount || this.moneyHash[this.assetId].cloneWithTokens('0'); - // this._fillMirror(); - // this.receive(utils.observe(this.state, 'assetId'), this._onChangeAssetId, this); - // this.receive(utils.observe(this.state, 'mirrorId'), this._onChangeMirrorId, this); - - // this.receive(utils.observe(this.state, 'paymentId'), this._updateGatewayDetails, this); - // this.receive(utils.observe(this.tx, 'recipient'), this._updateGatewayDetails, this); + const onHasMoneyHash = () => { + this.tx.amount = this.tx.amount || this.balance.cloneWithTokens('0'); + this.receive(utils.observe(this.tx, 'fee'), this._onChangeFee, this); + this.receive(utils.observe(this.tx, 'amount'), this._onChangeAmount, this); - // this.receive(utils.observe(this.state, 'paymentId'), this._updateGatewayPermisson, this); - // this.receive(utils.observe(this.tx, 'recipient'), this._updateGatewayPermisson, this); + this.receive(utils.observe(this.state, 'assetId'), this._onChangeAssetId, this); + this.receive(utils.observe(this.state, 'mirrorId'), this._onChangeMirrorId, this); - this.receive(utils.observe(this.tx, 'amount'), this._onChangeAmount, this); this.observe('mirror', this._onChangeAmountMirror); - // this.observe('gatewayDetails', this._updateWavesTxObject); - // this.receive(utils.observe(this.tx, 'amount'), this._updateWavesTxObject, this); - // this.receive(utils.observe(this.tx, 'recipient'), this._updateWavesTxObject, this); - // this.receive(utils.observe(this.tx, 'attachment'), this._updateWavesTxObject, this); - // - // this.observe('mirror', this._onChangeAmountMirror); - // this.observe(['gatewayAddressError', 'gatewayDetailsError', 'gatewayWrongAddress'], - // this._updateGatewayError); + this.receive(utils.observe(this.tx, 'amount'), this._updateWavesTxObject, this); + this.receive(utils.observe(this.tx, 'recipient'), this._updateWavesTxObject, this); + this.receive(utils.observe(this.tx, 'attachment'), this._updateWavesTxObject, this); - this._onUpdateFee(); + this._onUpdateRecipient(); + this._onChangeFee(); this._setMinAndMaxAmount(); this._onChangeBaseAssets(); - // this._updateGatewayDetails(); - // this._updateGatewayPermisson(); + this._updateWavesTxObject(); + this._fillMirror(); }; if (!this.state.moneyHash) { @@ -310,37 +157,25 @@ } this.receive(utils.observe(this.state, 'moneyHash'), () => { - this._onUpdateFee(); + this._onChangeFee(); this._setMinAndMaxAmount(); this._onChangeBaseAssets(); - // this._updateGatewayDetails(); }); - this._onChangeBaseAssets(); - this._updateWavesTxObject(); } setSendMode(mode) { this.onChangeMode({ mode }); } - onSignCoinomatStart() { - this.signInProgress = true; - } - - onSignCoinomatEnd() { - this.signInProgress = false; - } - + /** + * @return {Signable} + */ createTx() { - const toGateway = this.outerSendMode && this.gatewayDetails; - const fee = toGateway ? this.tx.amount.cloneWithTokens(toGateway.gatewayFee) : null; const attachmentString = this.tx.attachment ? this.tx.attachment.toString() : ''; const tx = waves.node.transactions.createTransaction({ ...this.tx, - recipient: toGateway ? this.gatewayDetails.address : this.tx.recipient, - attachment: utils.stringToBytes(toGateway ? this.gatewayDetails.attachment : attachmentString), - amount: toGateway ? this.tx.amount.add(fee) : this.tx.amount + attachment: utils.stringToBytes(attachmentString) }); const signable = ds.signature.getSignatureApi().makeSignable({ @@ -353,7 +188,7 @@ onSignTx(signable) { analytics.send({ name: 'Transfer Continue Click', target: 'ui' }); - this.onContinue({ signable }); + this.onSign({ signable }); } fillMax() { @@ -436,32 +271,16 @@ } } - /** - * @return {boolean} - */ - isMoneroNotIntegratedAddress() { - const moneroAddressLength = 95; - const assetIsMonero = this.state.assetId === WavesApp.defaultAssets.XMR; - return assetIsMonero && this.tx.recipient.length === moneroAddressLength; - } - - getGatewayDetails() { - this._onChangeAssetId(); - } - /** * @private */ _updateWavesTxObject() { - const toGateway = this.outerSendMode && this.gatewayDetails; - const fee = toGateway ? this.tx.amount.cloneWithTokens(toGateway.gatewayFee) : null; const attachmentString = this.tx.attachment ? this.tx.attachment.toString() : ''; const isWavesAddress = user.isValidAddress(this.tx.recipient); this.wavesTx = { ...this.wavesTx, - recipient: toGateway ? this.gatewayDetails.address : isWavesAddress && this.tx.recipient || '', - attachment: utils.stringToBytes(toGateway ? this.gatewayDetails.attachment : attachmentString), - amount: toGateway ? this.tx.amount.add(fee) : this.tx.amount, + recipient: isWavesAddress && this.tx.recipient || '', + attachment: utils.stringToBytes(attachmentString), assetId: this.assetId }; } @@ -473,24 +292,12 @@ if (this.tx.amount.getTokens().gt(0) || this.tx.recipient) { this.wavesSend.$setDirty(true); this.wavesSend.$setSubmitted(true); + if (this.wavesSend.amount) { + this.wavesSend.amount.$setTouched(true); + } } } - /** - * @private - */ - _onChangeBankMode() { - if (this.toBankMode && !this.isLira) { - this.tx.recipient = BANK_RECIPIENT; - this.termsIsPending = true; - } else { - this.tx.recipient = ''; - this.termsIsPending = false; - } - - this._updateGatewayPermisson(); - } - /** * @private */ @@ -525,13 +332,12 @@ this.tx.amount = this.moneyHash[this.assetId].cloneWithTokens('0'); this.mirror = this.moneyHash[this.mirrorId].cloneWithTokens('0'); - this._updateGatewayPermisson(); } /** * @private */ - _onUpdateFee() { + _onChangeFee() { this.feeList = [this.tx.fee]; const feeHash = utils.groupMoney(this.feeList); @@ -551,15 +357,18 @@ if (this.assetId === this.mirrorId) { this.noMirror = true; } else { - waves.utils.getRate(this.assetId, this.mirrorId).then((rate) => { + waves.utils.getRate(this.assetId, this.mirrorId).then(rate => { this.noMirror = rate.eq(0); }); } } + /** + * @private + */ _setMinAndMaxAmount() { - this.minAmount = this.state.moneyHash[this.state.assetId].cloneWithTokens('0'); - this.maxAmount = this.moneyHash[this.assetId]; + this.minAmount = this.balance.cloneWithTokens('0'); + this.maxAmount = this.balance; } /** @@ -569,7 +378,6 @@ if (!this.noMirror && this.focus === 'amount') { this._fillMirror(); } - } /** @@ -590,7 +398,7 @@ return; } - waves.utils.getRate(this.assetId, this.mirrorId).then((rate) => { + waves.utils.getRate(this.assetId, this.mirrorId).then(rate => { this.mirror = this.tx.amount.convertTo(this.moneyHash[this.mirrorId].asset, rate); }); } @@ -604,7 +412,7 @@ return null; } - waves.utils.getRate(this.mirrorId, this.assetId).then((rate) => { + waves.utils.getRate(this.mirrorId, this.assetId).then(rate => { this.tx.amount = this.mirror.convertTo(this.moneyHash[this.assetId].asset, rate); }); } @@ -613,21 +421,21 @@ * @private */ _onUpdateRecipient() { + this._checkOuterBlockchains(); this._validateForm(); } /** * @private */ - _updateGatewayPermisson() { - this.gatewayDetailsError = this.outerSendMode ? !this.isGatewayAccepted : this.gatewayDetailsError; - } - - /** - * @private - */ - _updateGatewayError() { - this.gatewayError = this.gatewayAddressError || this.gatewayDetailsError || this.gatewayWrongAddress; + _checkOuterBlockchains() { + const outerChain = outerBlockchains[this.assetId]; + const isValidWavesAddress = user.isValidAddress(this.tx.recipient); + const gatewayAddress = !isValidWavesAddress && + outerChain && outerChain.isValidAddress(this.tx.recipient); + if (gatewayAddress) { + this.setSendMode('gateway'); + } } } @@ -639,18 +447,15 @@ 'Base', '$scope', 'utils', - 'createPoll', 'waves', - 'configService', - 'outerBlockchains', 'user', - 'gatewayService' + 'outerBlockchains' ]; angular.module('app.ui').component('wWavesSend', { bindings: { state: '<', - onContinue: '&', + onSign: '&', onChangeMode: '&' }, templateUrl: 'modules/utils/modals/sendAsset/components/singleSend/wavesSend/waves-send.html', @@ -658,11 +463,3 @@ controller }); })(); - -/** - * @typedef {object} ISendTx - * @property {Money} fee - * @property {Money} amount - * @property {string} recipient - * @property {string} attachment - */ diff --git a/src/modules/utils/modals/sendAsset/components/singleSend/wavesSend/waves-send.html b/src/modules/utils/modals/sendAsset/components/singleSend/wavesSend/waves-send.html index 880a85252a..dcd9248899 100644 --- a/src/modules/utils/modals/sendAsset/components/singleSend/wavesSend/waves-send.html +++ b/src/modules/utils/modals/sendAsset/components/singleSend/wavesSend/waves-send.html @@ -19,7 +19,7 @@
+ amount="$ctrl.tx.amount">
-