MCPcopy
hub / github.com/bitpay/wallet / purchaseAttempt

Method purchaseAttempt

src/providers/in-app-browser/card.ts:807–849  ·  view source on GitHub ↗
(event)

Source from the content-addressed store, hash-verified

805 }
806
807 async purchaseAttempt(event) {
808 const { invoiceId } = event.data.params;
809
810 this.logger.debug('Incoming-data: Handling bitpay invoice');
811 try {
812 const details = await this.payproProvider.getPayProOptions(
813 `${this.BITPAY_API_URL}/i/${invoiceId}`
814 );
815
816 let hasWallets = {};
817 let availableWallets = [];
818 for (const option of details.paymentOptions) {
819 const fundedWallets = this.profileProvider.getWallets({
820 coin: option.currency.toLowerCase(),
821 network: option.network,
822 minAmount: option.estimatedAmount
823 });
824 if (fundedWallets.length === 0) {
825 option.disabled = true;
826 } else {
827 hasWallets[option.currency.toLowerCase()] = fundedWallets.length;
828 availableWallets.push(option);
829 }
830 }
831
832 const stateParams = {
833 payProOptions: details,
834 walletCardRedir: true,
835 hasWallets
836 };
837
838 let nextView = {
839 name: 'SelectInvoicePage',
840 params: stateParams
841 };
842 this.events.publish('IncomingDataRedir', nextView);
843 } catch (err) {
844 this.events.publish('incomingDataError', err);
845 this.logger.error(err);
846 }
847
848 this.hide();
849 }
850
851 async toggleShow(event) {
852 this.events.publish('showHideUpdate', 'inProgress');

Callers 1

initMethod · 0.95

Calls 5

hideMethod · 0.95
debugMethod · 0.80
getPayProOptionsMethod · 0.80
errorMethod · 0.80
getWalletsMethod · 0.45

Tested by

no test coverage detected