Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/utils/CBPayInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ export interface CBPayInstanceType {
export class CBPayInstance implements CBPayInstanceType {
private pixel: CoinbasePixel;
private options: InternalExperienceOptions;
private targetElement: HTMLElement | null;

constructor(options: CBPayInstanceConstructorArguments) {
this.targetElement = null;
this.options = options;
this.pixel = new CoinbasePixel({
...options,
Expand All @@ -40,9 +42,9 @@ export class CBPayInstance implements CBPayInstanceType {
});

if (options.target) {
const targetElement = document.querySelector(options.target);
if (targetElement) {
targetElement.addEventListener('click', this.open);
this.targetElement = document.querySelector(options.target);
if (this.targetElement) {
this.targetElement.addEventListener('click', this.open);
}
}
}
Expand Down Expand Up @@ -84,6 +86,9 @@ export class CBPayInstance implements CBPayInstanceType {
};

public destroy = (): void => {
if (this.targetElement) {
this.targetElement.removeEventListener('click', this.open);
}
this.pixel.destroy();
};
}