Skip to content

Commit c38f798

Browse files
authored
[BREAKING] - Create get token standard method / Standardize ERC721/1155/20 method names (#667)
* add getTokenStandard method * standardize method name patterns * improve typing
1 parent d7ec98b commit c38f798

19 files changed

+1031
-258
lines changed

src/ComposableController.test.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -97,22 +97,22 @@ describe('ComposableController', () => {
9797
preferencesController.subscribe(listener),
9898
onNetworkStateChange: (listener) =>
9999
networkController.subscribe(listener),
100-
getAssetName: assetContractController.getAssetName.bind(
100+
getERC721AssetName: assetContractController.getERC721AssetName.bind(
101101
assetContractController,
102102
),
103-
getAssetSymbol: assetContractController.getAssetSymbol.bind(
103+
getERC721AssetSymbol: assetContractController.getERC721AssetSymbol.bind(
104104
assetContractController,
105105
),
106-
getCollectibleTokenURI: assetContractController.getCollectibleTokenURI.bind(
106+
getERC721TokenURI: assetContractController.getERC721TokenURI.bind(
107107
assetContractController,
108108
),
109-
getOwnerOf: assetContractController.getOwnerOf.bind(
109+
getERC721OwnerOf: assetContractController.getERC721OwnerOf.bind(
110110
assetContractController,
111111
),
112-
balanceOfERC1155Collectible: assetContractController.balanceOfERC1155Collectible.bind(
112+
getERC1155BalanceOf: assetContractController.getERC1155BalanceOf.bind(
113113
assetContractController,
114114
),
115-
uriERC1155Collectible: assetContractController.uriERC1155Collectible.bind(
115+
getERC1155TokenURI: assetContractController.getERC1155TokenURI.bind(
116116
assetContractController,
117117
),
118118
});
@@ -178,22 +178,22 @@ describe('ComposableController', () => {
178178
preferencesController.subscribe(listener),
179179
onNetworkStateChange: (listener) =>
180180
networkController.subscribe(listener),
181-
getAssetName: assetContractController.getAssetName.bind(
181+
getERC721AssetName: assetContractController.getERC721AssetName.bind(
182182
assetContractController,
183183
),
184-
getAssetSymbol: assetContractController.getAssetSymbol.bind(
184+
getERC721AssetSymbol: assetContractController.getERC721AssetSymbol.bind(
185185
assetContractController,
186186
),
187-
getCollectibleTokenURI: assetContractController.getCollectibleTokenURI.bind(
187+
getERC721TokenURI: assetContractController.getERC721TokenURI.bind(
188188
assetContractController,
189189
),
190-
getOwnerOf: assetContractController.getOwnerOf.bind(
190+
getERC721OwnerOf: assetContractController.getERC721OwnerOf.bind(
191191
assetContractController,
192192
),
193-
balanceOfERC1155Collectible: assetContractController.balanceOfERC1155Collectible.bind(
193+
getERC1155BalanceOf: assetContractController.getERC1155BalanceOf.bind(
194194
assetContractController,
195195
),
196-
uriERC1155Collectible: assetContractController.uriERC1155Collectible.bind(
196+
getERC1155TokenURI: assetContractController.getERC1155TokenURI.bind(
197197
assetContractController,
198198
),
199199
});

src/assets/AssetsContractController.test.ts

+15-13
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@ const ERC1155_ID =
1414

1515
const TEST_ACCOUNT_PUBLIC_ADDRESS =
1616
'0x5a3CA5cD63807Ce5e4d7841AB32Ce6B6d9BbBa2D';
17-
1817
describe('AssetsContractController', () => {
1918
let assetsContract: AssetsContractController;
20-
2119
beforeEach(() => {
2220
assetsContract = new AssetsContractController();
2321
});
@@ -36,11 +34,11 @@ describe('AssetsContractController', () => {
3634

3735
it('should get balance of ERC-20 token contract correctly', async () => {
3836
assetsContract.configure({ provider: MAINNET_PROVIDER });
39-
const UNIBalance = await assetsContract.getBalanceOf(
37+
const UNIBalance = await assetsContract.getERC20BalanceOf(
4038
ERC20_UNI_ADDRESS,
4139
TEST_ACCOUNT_PUBLIC_ADDRESS,
4240
);
43-
const UNINoBalance = await assetsContract.getBalanceOf(
41+
const UNINoBalance = await assetsContract.getERC20BalanceOf(
4442
ERC20_UNI_ADDRESS,
4543
'0x202637dAAEfbd7f131f90338a4A6c69F6Cd5CE91',
4644
);
@@ -50,7 +48,7 @@ describe('AssetsContractController', () => {
5048

5149
it('should get ERC-721 collectible tokenId correctly', async () => {
5250
assetsContract.configure({ provider: MAINNET_PROVIDER });
53-
const tokenId = await assetsContract.getCollectibleTokenId(
51+
const tokenId = await assetsContract.getERC721CollectibleTokenId(
5452
ERC721_GODS_ADDRESS,
5553
'0x9a90bd8d1149a88b42a99cf62215ad955d6f498a',
5654
0,
@@ -60,7 +58,7 @@ describe('AssetsContractController', () => {
6058

6159
it('should get ERC-721 collectible tokenURI correctly', async () => {
6260
assetsContract.configure({ provider: MAINNET_PROVIDER });
63-
const tokenId = await assetsContract.getCollectibleTokenURI(
61+
const tokenId = await assetsContract.getERC721TokenURI(
6462
ERC721_GODS_ADDRESS,
6563
'0',
6664
);
@@ -70,7 +68,7 @@ describe('AssetsContractController', () => {
7068
it('should throw an error when address given is not an ERC-721 collectible', async () => {
7169
assetsContract.configure({ provider: MAINNET_PROVIDER });
7270
const result = async () => {
73-
await assetsContract.getCollectibleTokenURI(
71+
await assetsContract.getERC721TokenURI(
7472
'0x0000000000000000000000000000000000000000',
7573
'0',
7674
);
@@ -82,25 +80,29 @@ describe('AssetsContractController', () => {
8280

8381
it('should get ERC-721 collectible name', async () => {
8482
assetsContract.configure({ provider: MAINNET_PROVIDER });
85-
const name = await assetsContract.getAssetName(ERC721_GODS_ADDRESS);
83+
const name = await assetsContract.getERC721AssetName(ERC721_GODS_ADDRESS);
8684
expect(name).toStrictEqual('Gods Unchained');
8785
});
8886

8987
it('should get ERC-721 collectible symbol', async () => {
9088
assetsContract.configure({ provider: MAINNET_PROVIDER });
91-
const symbol = await assetsContract.getAssetSymbol(ERC721_GODS_ADDRESS);
89+
const symbol = await assetsContract.getERC721AssetSymbol(
90+
ERC721_GODS_ADDRESS,
91+
);
9292
expect(symbol).toStrictEqual('GODS');
9393
});
9494

9595
it('should get ERC-20 token decimals', async () => {
9696
assetsContract.configure({ provider: MAINNET_PROVIDER });
97-
const symbol = await assetsContract.getTokenDecimals(ERC20_DAI_ADDRESS);
97+
const symbol = await assetsContract.getERC20TokenDecimals(
98+
ERC20_DAI_ADDRESS,
99+
);
98100
expect(Number(symbol)).toStrictEqual(18);
99101
});
100102

101103
it('should get ERC-721 collectible ownership', async () => {
102104
assetsContract.configure({ provider: MAINNET_PROVIDER });
103-
const tokenId = await assetsContract.getOwnerOf(
105+
const tokenId = await assetsContract.getERC721OwnerOf(
104106
ERC721_GODS_ADDRESS,
105107
'148332',
106108
);
@@ -118,7 +120,7 @@ describe('AssetsContractController', () => {
118120

119121
it('should get the balance of a ERC-1155 collectible for a given address', async () => {
120122
assetsContract.configure({ provider: MAINNET_PROVIDER });
121-
const balance = await assetsContract.balanceOfERC1155Collectible(
123+
const balance = await assetsContract.getERC1155BalanceOf(
122124
TEST_ACCOUNT_PUBLIC_ADDRESS,
123125
ERC1155_ADDRESS,
124126
ERC1155_ID,
@@ -129,7 +131,7 @@ describe('AssetsContractController', () => {
129131
it('should get the URI of a ERC-1155 collectible', async () => {
130132
assetsContract.configure({ provider: MAINNET_PROVIDER });
131133
const expectedUri = `https://api.opensea.io/api/v1/metadata/${ERC1155_ADDRESS}/0x{id}`;
132-
const uri = await assetsContract.uriERC1155Collectible(
134+
const uri = await assetsContract.getERC1155TokenURI(
133135
ERC1155_ADDRESS,
134136
ERC1155_ID,
135137
);

0 commit comments

Comments
 (0)