Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding ERC721 detection to TokensController #524

Merged
merged 13 commits into from
Jul 20, 2021
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