Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions src/ComposableController.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sinon from 'sinon';
import type { Patch } from 'immer';
import { TokensController } from './assets/TokensController';
import { CollectiblesController } from './assets/CollectiblesController';
import { NftController } from './assets/NftController';
import { AddressBookController } from './user/AddressBookController';
import { EnsController } from './third-party/EnsController';
import {
Expand Down Expand Up @@ -123,7 +123,7 @@ const setupControllers = () => {
messenger.subscribe('NetworkController:stateChange', listener),
});

const collectiblesController = new CollectiblesController({
const nftController = new NftController({
onPreferencesStateChange: (listener) =>
preferencesController.subscribe(listener),
onNetworkStateChange: (listener) =>
Expand All @@ -146,7 +146,7 @@ const setupControllers = () => {
getERC1155TokenURI: assetContractController.getERC1155TokenURI.bind(
assetContractController,
),
onCollectibleAdded: jest.fn(),
onNftAdded: jest.fn(),
});

const tokensController = new TokensController({
Expand All @@ -162,7 +162,7 @@ const setupControllers = () => {
networkController,
preferencesController,
assetContractController,
collectiblesController,
nftController,
tokensController,
};
};
Expand All @@ -179,15 +179,15 @@ describe('ComposableController', () => {
composableMessenger,
networkController,
assetContractController,
collectiblesController,
nftController,
tokensController,
preferencesController,
} = setupControllers();

const controller = new ComposableController(
[
new AddressBookController(),
collectiblesController,
nftController,
assetContractController,
new EnsController(),
networkController,
Expand All @@ -200,10 +200,10 @@ describe('ComposableController', () => {
expect(controller.state).toStrictEqual({
AddressBookController: { addressBook: {} },
AssetsContractController: {},
CollectiblesController: {
allCollectibleContracts: {},
allCollectibles: {},
ignoredCollectibles: [],
NftController: {
allNftContracts: {},
allNfts: {},
ignoredNfts: [],
},
TokensController: {
allTokens: {},
Expand Down Expand Up @@ -231,7 +231,7 @@ describe('ComposableController', () => {
lostIdentities: {},
selectedAddress: '',
useTokenDetection: true,
useCollectibleDetection: false,
useNftDetection: false,
openSeaEnabled: false,
},
});
Expand All @@ -245,15 +245,15 @@ describe('ComposableController', () => {
composableMessenger,
networkController,
assetContractController,
collectiblesController,
nftController,
tokensController,
preferencesController,
} = setupControllers();

const controller = new ComposableController(
[
new AddressBookController(),
collectiblesController,
nftController,
assetContractController,
new EnsController(),
networkController,
Expand All @@ -264,14 +264,14 @@ describe('ComposableController', () => {
);
expect(controller.flatState).toStrictEqual({
addressBook: {},
allCollectibleContracts: {},
allCollectibles: {},
allNftContracts: {},
allNfts: {},
allTokens: {},
ensEntries: {},
featureFlags: {},
frequentRpcList: [],
identities: {},
ignoredCollectibles: [],
ignoredNfts: [],
ignoredTokens: [],
allIgnoredTokens: {},
detectedTokens: [],
Expand All @@ -284,7 +284,7 @@ describe('ComposableController', () => {
provider: { type: 'mainnet', chainId: NetworksChainId.mainnet },
selectedAddress: '',
useTokenDetection: true,
useCollectibleDetection: false,
useNftDetection: false,
openSeaEnabled: false,
suggestedAssets: [],
tokens: [],
Expand Down
24 changes: 12 additions & 12 deletions src/assets/AssetsContractController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ describe('AssetsContractController', () => {
messenger.clearEventSubscriptions('NetworkController:stateChange');
});

it('should get ERC-721 collectible tokenId correctly', async () => {
it('should get ERC-721 NFT tokenId correctly', async () => {
const { assetsContract, messenger } = setupControllers();
assetsContract.configure({ provider: MAINNET_PROVIDER });
const tokenId = await assetsContract.getERC721CollectibleTokenId(
const tokenId = await assetsContract.getERC721NftTokenId(
ERC721_GODS_ADDRESS,
'0x9a90bd8d1149a88b42a99cf62215ad955d6f498a',
0,
Expand Down Expand Up @@ -190,7 +190,7 @@ describe('AssetsContractController', () => {
messenger.clearEventSubscriptions('NetworkController:stateChange');
});

it('should get ERC-721 collectible tokenURI correctly', async () => {
it('should get ERC-721 NFT tokenURI correctly', async () => {
const { assetsContract, messenger } = setupControllers();
assetsContract.configure({ provider: MAINNET_PROVIDER });
const tokenId = await assetsContract.getERC721TokenURI(
Expand All @@ -201,7 +201,7 @@ describe('AssetsContractController', () => {
messenger.clearEventSubscriptions('NetworkController:stateChange');
});

it('should throw an error when address given is not an ERC-721 collectible', async () => {
it('should throw an error when address given is not an ERC-721 NFT', async () => {
const { assetsContract, messenger } = setupControllers();
assetsContract.configure({ provider: MAINNET_PROVIDER });
const result = async () => {
Expand All @@ -216,15 +216,15 @@ describe('AssetsContractController', () => {
messenger.clearEventSubscriptions('NetworkController:stateChange');
});

it('should get ERC-721 collectible name', async () => {
it('should get ERC-721 NFT name', async () => {
const { assetsContract, messenger } = setupControllers();
assetsContract.configure({ provider: MAINNET_PROVIDER });
const name = await assetsContract.getERC721AssetName(ERC721_GODS_ADDRESS);
expect(name).toStrictEqual('Gods Unchained');
messenger.clearEventSubscriptions('NetworkController:stateChange');
});

it('should get ERC-721 collectible symbol', async () => {
it('should get ERC-721 NFT symbol', async () => {
const { assetsContract, messenger } = setupControllers();
assetsContract.configure({ provider: MAINNET_PROVIDER });
const symbol = await assetsContract.getERC721AssetSymbol(
Expand All @@ -234,7 +234,7 @@ describe('AssetsContractController', () => {
messenger.clearEventSubscriptions('NetworkController:stateChange');
});

it('should throw missing provider error when getting ERC-721 collectible symbol when missing provider', async () => {
it('should throw missing provider error when getting ERC-721 NFT symbol when missing provider', async () => {
const { assetsContract, messenger } = setupControllers();
await expect(
assetsContract.getERC721AssetSymbol(ERC721_GODS_ADDRESS),
Expand All @@ -252,7 +252,7 @@ describe('AssetsContractController', () => {
messenger.clearEventSubscriptions('NetworkController:stateChange');
});

it('should get ERC-721 collectible ownership', async () => {
it('should get ERC-721 NFT ownership', async () => {
const { assetsContract, messenger } = setupControllers();
assetsContract.configure({ provider: MAINNET_PROVIDER });
const tokenId = await assetsContract.getERC721OwnerOf(
Expand All @@ -263,7 +263,7 @@ describe('AssetsContractController', () => {
messenger.clearEventSubscriptions('NetworkController:stateChange');
});

it('should throw missing provider error when getting ERC-721 collectible ownership', async () => {
it('should throw missing provider error when getting ERC-721 NFT ownership', async () => {
const { assetsContract, messenger } = setupControllers();
await expect(
assetsContract.getERC721OwnerOf(ERC721_GODS_ADDRESS, '148332'),
Expand Down Expand Up @@ -319,7 +319,7 @@ describe('AssetsContractController', () => {
messenger.clearEventSubscriptions('NetworkController:stateChange');
});

it('should get the balance of a ERC-1155 collectible for a given address', async () => {
it('should get the balance of a ERC-1155 NFT for a given address', async () => {
const { assetsContract, messenger } = setupControllers();
assetsContract.configure({ provider: MAINNET_PROVIDER });
const balance = await assetsContract.getERC1155BalanceOf(
Expand All @@ -331,7 +331,7 @@ describe('AssetsContractController', () => {
messenger.clearEventSubscriptions('NetworkController:stateChange');
});

it('should throw missing provider error when getting the balance of a ERC-1155 collectible when missing provider', async () => {
it('should throw missing provider error when getting the balance of a ERC-1155 NFT when missing provider', async () => {
const { assetsContract, messenger } = setupControllers();
await expect(
assetsContract.getERC1155BalanceOf(
Expand All @@ -343,7 +343,7 @@ describe('AssetsContractController', () => {
messenger.clearEventSubscriptions('NetworkController:stateChange');
});

it('should get the URI of a ERC-1155 collectible', async () => {
it('should get the URI of a ERC-1155 NFT', async () => {
const { assetsContract, messenger } = setupControllers();
assetsContract.configure({ provider: MAINNET_PROVIDER });
const expectedUri = `https://api.opensea.io/api/v1/metadata/${ERC1155_ADDRESS}/0x{id}`;
Expand Down
38 changes: 17 additions & 21 deletions src/assets/AssetsContractController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import type { PreferencesState } from '../user/PreferencesController';
import { IPFS_DEFAULT_GATEWAY_URL } from '../constants';
import { SupportedTokenDetectionNetworks } from '../util';
import { NetworkState } from '../network/NetworkController';
import { ERC721Standard } from './Standards/CollectibleStandards/ERC721/ERC721Standard';
import { ERC1155Standard } from './Standards/CollectibleStandards/ERC1155/ERC1155Standard';
import { ERC721Standard } from './Standards/NftStandards/ERC721/ERC721Standard';
import { ERC1155Standard } from './Standards/NftStandards/ERC1155/ERC1155Standard';
import { ERC20Standard } from './Standards/ERC20Standard';

/**
Expand Down Expand Up @@ -170,22 +170,18 @@ export class AssetsContractController extends BaseController<
*
* @param address - ERC721 asset contract address.
* @param selectedAddress - Current account public address.
* @param index - A collectible counter less than `balanceOf(selectedAddress)`.
* @param index - An NFT counter less than `balanceOf(selectedAddress)`.
* @returns Promise resolving to token identifier for the 'index'th asset assigned to 'selectedAddress'.
*/
getERC721CollectibleTokenId(
getERC721NftTokenId(
address: string,
selectedAddress: string,
index: number,
): Promise<string> {
if (this.erc721Standard === undefined) {
throw new Error(MISSING_PROVIDER_ERROR);
}
return this.erc721Standard.getCollectibleTokenId(
address,
selectedAddress,
index,
);
return this.erc721Standard.getNftTokenId(address, selectedAddress, index);
}

/**
Expand Down Expand Up @@ -328,50 +324,50 @@ export class AssetsContractController extends BaseController<
* Query for balance of a given ERC 1155 token.
*
* @param userAddress - Wallet public address.
* @param collectibleAddress - ERC1155 asset contract address.
* @param collectibleId - ERC1155 asset identifier.
* @param nftAddress - ERC1155 asset contract address.
* @param nftId - ERC1155 asset identifier.
* @returns Promise resolving to the 'balanceOf'.
*/
async getERC1155BalanceOf(
userAddress: string,
collectibleAddress: string,
collectibleId: string,
nftAddress: string,
nftId: string,
): Promise<number> {
if (this.erc1155Standard === undefined) {
throw new Error(MISSING_PROVIDER_ERROR);
}
return await this.erc1155Standard.getBalanceOf(
collectibleAddress,
nftAddress,
userAddress,
collectibleId,
nftId,
);
}

/**
* Transfer single ERC1155 token.
*
* @param collectibleAddress - ERC1155 token address.
* @param nftAddress - ERC1155 token address.
* @param senderAddress - ERC1155 token sender.
* @param recipientAddress - ERC1155 token recipient.
* @param collectibleId - ERC1155 token id.
* @param nftId - ERC1155 token id.
* @param qty - Quantity of tokens to be sent.
* @returns Promise resolving to the 'transferSingle' ERC1155 token.
*/
async transferSingleERC1155(
collectibleAddress: string,
nftAddress: string,
senderAddress: string,
recipientAddress: string,
collectibleId: string,
nftId: string,
qty: string,
): Promise<void> {
if (this.erc1155Standard === undefined) {
throw new Error(MISSING_PROVIDER_ERROR);
}
return await this.erc1155Standard.transferSingle(
collectibleAddress,
nftAddress,
senderAddress,
recipientAddress,
collectibleId,
nftId,
qty,
);
}
Expand Down
Loading