Skip to content

Commit

Permalink
add preference to enable/disable collectible detection
Browse files Browse the repository at this point in the history
  • Loading branch information
adonesky1 committed Nov 22, 2021
1 parent a1270ae commit c02a0ff
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/assets/CollectibleDetectionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export interface CollectibleDetectionConfig extends BaseConfig {
interval: number;
networkType: NetworkType;
selectedAddress: string;
enabled: boolean;
}

/**
Expand Down Expand Up @@ -229,13 +230,23 @@ export class CollectibleDetectionController extends BaseController<
interval: DEFAULT_INTERVAL,
networkType: MAINNET,
selectedAddress: '',
enabled: false,
};
this.initialize();
this.getCollectiblesState = getCollectiblesState;
onPreferencesStateChange(({ selectedAddress }) => {
onPreferencesStateChange(({ selectedAddress, useCollectibleDetection }) => {
const {
selectedAddress: previouslySelectedAddress,
enabled,
} = this.config;

const actualSelectedAddress = this.config.selectedAddress;
if (selectedAddress !== actualSelectedAddress) {
this.configure({ selectedAddress });

if (
selectedAddress !== previouslySelectedAddress ||
useCollectibleDetection !== enabled
) {
this.configure({ selectedAddress, enabled: useCollectibleDetection });
this.detectCollectibles();
}
});
Expand All @@ -251,7 +262,7 @@ export class CollectibleDetectionController extends BaseController<
* Start polling for the currency rate.
*/
async start() {
if (!this.isMainnet() || this.disabled) {
if (!this.isMainnet() || !this.config.enabled) {
return;
}

Expand Down Expand Up @@ -298,7 +309,7 @@ export class CollectibleDetectionController extends BaseController<
*/
async detectCollectibles() {
/* istanbul ignore if */
if (!this.isMainnet() || this.disabled) {
if (!this.isMainnet() || !this.config.enabled) {
return;
}
const requestedSelectedAddress = this.config.selectedAddress;
Expand Down

0 comments on commit c02a0ff

Please sign in to comment.