Skip to content

Commit

Permalink
added handler for desktop universal mode
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnathanWhite committed Oct 13, 2021
1 parent 629db1b commit 783e3e5
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion src/providers/incoming-data/incoming-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { Logger } from '../logger/logger';
import { OnGoingProcessProvider } from '../on-going-process/on-going-process';
import { PayproProvider } from '../paypro/paypro';
import { PersistenceProvider } from '../persistence/persistence';
import { PlatformProvider } from '../platform/platform';
import { ProfileProvider } from '../profile/profile';

export interface RedirParams {
Expand Down Expand Up @@ -53,7 +54,8 @@ export class IncomingDataProvider {
private iabCardProvider: IABCardProvider,
private persistenceProvider: PersistenceProvider,
private bitPayIdProvider: BitPayIdProvider,
private invoiceProvider: InvoiceProvider
private invoiceProvider: InvoiceProvider,
private platformProvider: PlatformProvider
) {
this.logger.debug('IncomingDataProvider initialized');
this.events.subscribe('unlockInvoice', paymentUrl =>
Expand Down Expand Up @@ -146,6 +148,10 @@ export class IncomingDataProvider {
return !!/(wallet\/wc|wc:)/g.exec(data);
}

private isValidInvoiceIntentUri(data: string): boolean {
return !!/^bitpay:\/\/(test\.|staging\.)?bitpay\.com\/i\/\w+/.exec(data);
}

public isValidBitcoinCashUriWithLegacyAddress(data: string): boolean {
data = this.sanitizeUri(data);
return !!this.bwcProvider
Expand Down Expand Up @@ -923,6 +929,12 @@ export class IncomingDataProvider {
if (this.isValidBitPayInvoice(data)) {
this.handleUnlock(data);
return true;
} else if (
this.platformProvider.isElectron &&
this.isValidInvoiceIntentUri(data)
) {
this.handleDesktopUnlock(data);
return true;

// Payment Protocol
} else if (this.isValidPayPro(data)) {
Expand Down Expand Up @@ -1609,4 +1621,25 @@ export class IncomingDataProvider {
.present();
}
}

public async handleDesktopUnlock(data: string) {
const invoiceId = data.split('i/')[1];
const url = data.replace('bitpay://', 'https://');
const { host } = new URL(url);
try {
// setting attempt 4 as a check to see if invoice is locked
await this.payproProvider.getPayProOptions(url, true, 4);
await this.handleBitPayInvoice(url);
} catch (err) {
const verificationRequiredInfoSheet = this.actionSheetProvider.createInfoSheet(
'auth-required'
);
await verificationRequiredInfoSheet.present();
verificationRequiredInfoSheet.onDidDismiss(async () => {
await this.externalLinkProvider.open(
`https://${host}/id/verify?context=unlockvd&id=${invoiceId}`
);
});
}
}
}

0 comments on commit 783e3e5

Please sign in to comment.