Skip to content

Commit

Permalink
create brack for assets controller version 11-1-0, cherry picked #1577
Browse files Browse the repository at this point in the history
  • Loading branch information
tommasini committed Mar 19, 2024
1 parent b7efa4c commit 67aa60e
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
43 changes: 43 additions & 0 deletions packages/assets-controllers/src/NftController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,7 @@ describe('NftController', () => {
tokenId: '1',
favorite: false,
isCurrentlyOwned: true,
tokenURI: '',
});
});

Expand Down Expand Up @@ -1109,6 +1110,8 @@ describe('NftController', () => {
standard: 'ERC721',
favorite: false,
isCurrentlyOwned: true,
tokenURI:
'https://ipfs.gitcoin.co:443/api/v0/cat/QmPmt6EAaioN78ECnW5oCL8v2YvVSpoBjLCjrXhhsAvoov',
});

expect(
Expand Down Expand Up @@ -1233,6 +1236,8 @@ describe('NftController', () => {
isCurrentlyOwned: true,
imageOriginal: 'image.uri',
numberOfSales: 1,
tokenURI:
'https://api.opensea.io/api/v1/metadata/0x495f947276749Ce646f68AC8c248420045cb7b5e/0x5a3ca5cd63807ce5e4d7841ab32ce6b6d9bbba2d000000000000010000000001',
});
});

Expand Down Expand Up @@ -1343,6 +1348,8 @@ describe('NftController', () => {
standard: 'ERC721',
favorite: false,
isCurrentlyOwned: true,
tokenURI:
'https://ipfs.gitcoin.co:443/api/v0/cat/QmPmt6EAaioN78ECnW5oCL8v2YvVSpoBjLCjrXhhsAvoov',
});

expect(
Expand Down Expand Up @@ -1576,6 +1583,7 @@ describe('NftController', () => {
tokenId: ERC721_KUDOS_TOKEN_ID,
favorite: false,
isCurrentlyOwned: true,
tokenURI: '',
},
]);

Expand Down Expand Up @@ -1803,6 +1811,8 @@ describe('NftController', () => {
standard: 'ERC721',
favorite: false,
isCurrentlyOwned: true,
tokenURI:
'https://bafybeidf7aw7bmnmewwj4ayq3she2jfk5jrdpp24aaucf6fddzb3cfhrvm.ipfs.cloudflare-ipfs.com',
});
});

Expand Down Expand Up @@ -1941,6 +1951,7 @@ describe('NftController', () => {
standard: ERC721,
favorite: false,
isCurrentlyOwned: true,
tokenURI: '',
});
});
});
Expand Down Expand Up @@ -2303,6 +2314,38 @@ describe('NftController', () => {
};
await expect(result).rejects.toThrow(error);
});

it('should add NFT with null metadata if the ipfs gateway is disabled and opensea is disabled', async () => {
const { assetsContract, nftController, preferences } = setupController();

preferences.update({
isIpfsGatewayEnabled: false,
openSeaEnabled: false,
});

sinon
.stub(nftController, 'getNftURIAndStandard' as any)
.returns(['ipfs://*', ERC1155]);

assetsContract.configure({ provider: MAINNET_PROVIDER });
const { selectedAddress, chainId } = nftController.config;

await nftController.addNft(ERC1155_NFT_ADDRESS, ERC1155_NFT_ID);

expect(
nftController.state.allNfts[selectedAddress][chainId][0],
).toStrictEqual({
address: ERC1155_NFT_ADDRESS,
name: null,
description: null,
image: null,
tokenId: ERC1155_NFT_ID,
standard: ERC1155,
favorite: false,
isCurrentlyOwned: true,
tokenURI: 'ipfs://*',
});
});
});

describe('updateNftFavoriteStatus', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/assets-controllers/src/NftController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ export class NftController extends BaseController<NftConfig, NftState> {
description: object.description,
standard,
favorite: false,
tokenURI,
tokenURI: tokenURI ?? null,
};
} catch {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('PreferencesController', () => {
},
isMultiAccountBalancesEnabled: true,
showTestNetworks: false,
isIpfsGatewayEnabled: true,
});
});

Expand Down Expand Up @@ -199,4 +200,10 @@ describe('PreferencesController', () => {
controller.setShowTestNetworks(true);
expect(controller.state.showTestNetworks).toStrictEqual(true);
});

it('should set isIpfsGatewayEnabled', () => {
const controller = new PreferencesController();
controller.setIsIpfsGatewayEnabled(true);
expect(controller.state.isIpfsGatewayEnabled).toBe(true);
});
});
11 changes: 11 additions & 0 deletions packages/preferences-controller/src/PreferencesController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export interface PreferencesState extends BaseState {
isMultiAccountBalancesEnabled: boolean;
isIpfsGatewayEnabled: boolean;
showTestNetworks: boolean;
isIpfsGatewayEnabled: boolean;
}

/**
Expand Down Expand Up @@ -79,6 +80,7 @@ export class PreferencesController extends BaseController<
isMultiAccountBalancesEnabled: true,
isIpfsGatewayEnabled: true,
showTestNetworks: false,
isIpfsGatewayEnabled: true,
};
this.initialize();
}
Expand Down Expand Up @@ -305,6 +307,15 @@ export class PreferencesController extends BaseController<
setShowTestNetworks(showTestNetworks: boolean) {
this.update({ showTestNetworks });
}

/**
* A setter for the user allow to be fetched IPFS content
*
* @param isIpfsGatewayEnabled - true to enable ipfs source
*/
setIsIpfsGatewayEnabled(isIpfsGatewayEnabled: boolean) {
this.update({ isIpfsGatewayEnabled });
}
}

export default PreferencesController;

0 comments on commit 67aa60e

Please sign in to comment.