From b5e3ad417e40035b2e5e99edef1add73da765d7f Mon Sep 17 00:00:00 2001 From: Feiran Hu Date: Wed, 19 Oct 2022 12:37:08 -0400 Subject: [PATCH] upgrade beta payout page to include identities --- pages/debug/beta/payouts/create.vue | 144 +++++++++++++++++++++++++--- 1 file changed, 131 insertions(+), 13 deletions(-) diff --git a/pages/debug/beta/payouts/create.vue b/pages/debug/beta/payouts/create.vue index c09f197a..ad4601b8 100644 --- a/pages/debug/beta/payouts/create.vue +++ b/pages/debug/beta/payouts/create.vue @@ -5,19 +5,27 @@ - - + - - @@ -26,14 +34,63 @@ v-model="formData.destinationType" :items="destinationType" label="Destination Type" + @change="onDestinationTypeChange" /> +
+ +
+
Optional Identity:
+
+ + + + + + + + + + + + + + + + +
+ !!v || 'Field is required'] destinationType = ['address_book', 'wire', 'ach', 'sepa'] fiatDestinationTypes = new Set(['wire', 'ach', 'sepa']) blockchainDestinationTypes = new Set(['address_book']) + identityTypes = ['individual', 'business'] + supportedFiatPayoutCurrencies = ['USD'] + // TODO: we can probably implement an internal endpoint to get the supported currency pairs + supportedCryptoPayoutCurrencyPairs = new Map([ + ['USD', ['USD', 'BTC', 'ETH', 'MTC']], + ['BTC', ['USD', 'BTC']], + ['ETH', ['USD', 'ETH']], + ['MTC', ['USD', 'MTC']], + ['FLW', ['FLW']], + ['MAN', ['MAN']], + ['EUR', ['EUR']], + ]) + error = {} loading = false showError = false + + isCryptoPayout() { + return this.blockchainDestinationTypes.has(this.formData.destinationType) + } + + onCurrencyChange() { + // do nothing if it's not crypto payout + if (!this.isCryptoPayout()) { + return + } + // else update default toCurrency + const supportedToCurrencies = this.supportedCryptoPayoutCurrencyPairs.get( + this.formData.currency + ) + this.formData.toCurrency = supportedToCurrencies + ? supportedToCurrencies[0] + : '' + } + + onDestinationTypeChange() { + // update currency to default + this.formData.currency = this.isCryptoPayout() + ? Array.from(this.supportedCryptoPayoutCurrencyPairs.keys())[0] + : this.supportedFiatPayoutCurrencies[0] + this.onCurrencyChange() + } + onErrorSheetClosed() { this.error = {} this.showError = false @@ -115,20 +220,33 @@ export default class CreatePayoutClass extends Vue { const toAmountDetail = { currency: this.formData.toCurrency, } + const identityAddressObject = { + line1: this.formData.identityAddressLine1, + line2: this.formData.identityAddressLine2, + city: this.formData.identityAddressCity, + district: this.formData.identityAddressDistrict, + postalCode: this.formData.identityAddressPostalCode, + country: this.formData.identityAddressCountry, + } + const identityObject = { + type: this.formData.identityType, + name: this.formData.identityName, + addresses: [identityAddressObject], + } + const sourceObject = { + id: this.formData.sourceWalletId, + type: 'wallet', + identities: [identityObject], + } const payload: CreatePayoutPayload = { idempotencyKey: uuidv4(), + source: sourceObject, amount: amountDetail, destination: { id: this.formData.destination, type: this.formData.destinationType, }, } - if (this.formData.sourceWalletId) { - payload.source = { - id: this.formData.sourceWalletId, - type: 'wallet', - } - } if (this.blockchainDestinationTypes.has(this.formData.destinationType)) { payload.toAmount = toAmountDetail }