Skip to content

Commit

Permalink
adapting new collectiblesController shape (#648)
Browse files Browse the repository at this point in the history
* adapting new collectiblesController shape

* address feedback
  • Loading branch information
adonesky1 authored and MajorLift committed Oct 11, 2023
1 parent c4d50af commit 21d1d5a
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/assets/CollectiblesController.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { EventEmitter } from 'events';
import { BN, stripHexPrefix } from 'ethereumjs-util';
import { BN, stripHexPrefix, isHexString } from 'ethereumjs-util';
import { Mutex } from 'async-mutex';

import { BaseController, BaseConfig, BaseState } from '../BaseController';
import type { PreferencesState } from '../user/PreferencesController';
import type { NetworkState, NetworkType } from '../network/NetworkController';
Expand Down Expand Up @@ -492,6 +493,13 @@ export class CollectiblesController extends BaseController<
selectedAddress = this.config.selectedAddress;
}

// ensure that chainid matches dec format for both detection and manual flows
if (typeof chainId === 'string' && isHexString(chainId)) {
chainId = `${parseInt(chainId, 16)}` as const;
} else if (typeof chainId === 'number') {
chainId = `${chainId}` as const;
}

const collectibles = allCollectibles[selectedAddress]?.[chainId] || [];

const existingEntry: Collectible | undefined = collectibles.find(
Expand Down Expand Up @@ -571,6 +579,13 @@ export class CollectiblesController extends BaseController<
selectedAddress = this.config.selectedAddress;
}

// ensure that chainid matches dec format for both detection and manual flows
if (typeof chainId === 'string' && isHexString(chainId)) {
chainId = `${parseInt(chainId, 16)}` as const;
} else if (typeof chainId === 'number') {
chainId = `${chainId}` as const;
}

const collectibleContracts =
allCollectibleContracts[selectedAddress]?.[chainId] || [];

Expand Down

0 comments on commit 21d1d5a

Please sign in to comment.