Skip to content

Commit

Permalink
adding ERC721 detection to TokensController (#524)
Browse files Browse the repository at this point in the history
* adding ERC721 detection to TokensController

* modifying provider and config/state initialization

* add watchAsset tests

* lint fixes

* add more tests related to new functionality to TokensController

* addressing feedback

* lint

* fixing tests and try/catch

* small addition to allow pre-ignoring tokens

* remove await from stubs and lint

* removing redundant tests

* mistaken change to package.json

* clean up isERC721 flag tests + add conditional block to enhance our check of contract-maps in _detectERC721
  • Loading branch information
adonesky1 authored Jul 20, 2021
1 parent eb71baa commit 3ce45f9
Show file tree
Hide file tree
Showing 7 changed files with 1,136 additions and 120 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"eth-sig-util": "^3.0.0",
"ethereumjs-util": "^7.0.10",
"ethereumjs-wallet": "^1.0.1",
"ethers": "^5.4.1",
"ethjs-unit": "^0.1.6",
"ethjs-util": "^0.1.6",
"human-standard-collectible-abi": "^1.0.2",
Expand Down
10 changes: 10 additions & 0 deletions src/assets/AssetsDetectionController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,9 @@ describe('AssetsDetectionController', () => {
},
],
});
stub(tokensController, '_detectIsERC721').callsFake(() =>
Promise.resolve(false),
);
});

afterEach(() => {
Expand Down Expand Up @@ -580,6 +583,7 @@ describe('AssetsDetectionController', () => {
symbol: 'GNO',
decimals: 18,
image: undefined,
isERC721: false,
},
]);
});
Expand All @@ -595,6 +599,7 @@ describe('AssetsDetectionController', () => {
decimals: 18,
image: undefined,
symbol: 'GNO',
isERC721: false,
},
]);
getBalancesInSingleCall.resolves({
Expand All @@ -607,12 +612,14 @@ describe('AssetsDetectionController', () => {
decimals: 18,
image: undefined,
symbol: 'GNO',
isERC721: false,
},
{
address: '0x514910771AF9Ca656af840dff83E8264EcF986CA',
symbol: 'LINK',
decimals: 18,
image: undefined,
isERC721: false,
},
]);
});
Expand Down Expand Up @@ -667,6 +674,9 @@ describe('AssetsDetectionController', () => {
});

it('should subscribe to new sibling detecting assets when account changes', async () => {
stub(tokensController, '_instantiateNewEthersProvider').callsFake(
() => null,
);
const firstNetworkType = 'rinkeby';
const secondNetworkType = 'mainnet';
const firstAddress = '0x123';
Expand Down
15 changes: 11 additions & 4 deletions src/assets/TokenBalancesController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,21 +182,28 @@ describe('TokenBalancesController', () => {
const assetsContract = new AssetsContractController();
const network = new NetworkController();
const preferences = new PreferencesController();
const assets = new TokensController({
const tokensController = new TokensController({
onPreferencesStateChange: (listener) => preferences.subscribe(listener),
onNetworkStateChange: (listener) => network.subscribe(listener),
});

const supportsInterfaceStub = stub().returns(Promise.resolve(false));

stub(tokensController, '_createEthersContract').callsFake(() =>
Promise.resolve({ supportsInterface: supportsInterfaceStub }),
);

const tokenBalances = new TokenBalancesController(
{
onTokensStateChange: (listener) => assets.subscribe(listener),
onTokensStateChange: (listener) => tokensController.subscribe(listener),
getSelectedAddress: () => preferences.state.selectedAddress,
getBalanceOf: assetsContract.getBalanceOf.bind(assetsContract),
},
{ interval: 1337 },
);
const updateBalances = sandbox.stub(tokenBalances, 'updateBalances');
await assets.addToken('0x00', 'FOO', 18);
const { tokens } = assets.state;
await tokensController.addToken('0x00', 'FOO', 18);
const { tokens } = tokensController.state;
const found = tokens.filter((token: Token) => token.address === '0x00');
expect(found.length > 0).toBe(true);
expect(updateBalances.called).toBe(true);
Expand Down
1 change: 1 addition & 0 deletions src/assets/TokenRatesController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export interface Token {
symbol: string;
image?: string;
balanceError?: Error | null;
isERC721?: boolean;
}

/**
Expand Down
Loading

0 comments on commit 3ce45f9

Please sign in to comment.