Skip to content

Commit

Permalink
fix: don't load pay.js if already loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
Soc Sieng committed Jun 8, 2020
1 parent 4062b48 commit 1e457b6
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/lib/button-manager.ts
Expand Up @@ -61,8 +61,15 @@ export class ButtonManager {
return this.element;
}

private isGooglePayLoaded(): boolean {
return 'google' in (window || global) && !!google?.payments?.api?.PaymentsClient;
}

async mount(element: Element): Promise<void> {
await loadScript('https://pay.google.com/gp/p/js/pay.js');
if (!this.isGooglePayLoaded()) {
await loadScript('https://pay.google.com/gp/p/js/pay.js');
console.log('loaded');
}

this.element = element;
if (element) {
Expand Down

0 comments on commit 1e457b6

Please sign in to comment.