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

Upgrade controllers to 25.1.0 #3638

Merged
merged 11 commits into from
Feb 28, 2022
4 changes: 2 additions & 2 deletions app/components/Nav/Main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,8 @@ const Main = (props) => {
if (!asset) {
try {
asset = {};
asset.decimals = await AssetsContractController.getTokenDecimals(to);
asset.symbol = await AssetsContractController.getAssetSymbol(to);
asset.decimals = await AssetsContractController.getERC20TokenDecimals(to);
asset.symbol = await AssetsContractController.getERC721AssetSymbol(to);
// adding `to` here as well
asset.address = to;
} catch (e) {
Expand Down
4 changes: 2 additions & 2 deletions app/components/UI/AddCustomToken/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ export default class AddCustomToken extends PureComponent {
if (validated) {
const address = this.state.address;
const { AssetsContractController } = Engine.context;
const decimals = await AssetsContractController.getTokenDecimals(address);
const symbol = await AssetsContractController.getAssetSymbol(address);
const decimals = await AssetsContractController.getERC20TokenDecimals(address);
const symbol = await AssetsContractController.getERC721AssetSymbol(address);
this.setState({ decimals: String(decimals), symbol });
}
};
Expand Down
4 changes: 2 additions & 2 deletions app/components/UI/ApproveTransactionReview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@ class ApproveTransactionReview extends PureComponent {
const contract = tokenList[safeToChecksumAddress(to)];
if (!contract) {
try {
tokenDecimals = await AssetsContractController.getTokenDecimals(to);
tokenSymbol = await AssetsContractController.getAssetSymbol(to);
tokenDecimals = await AssetsContractController.getERC20TokenDecimals(to);
tokenSymbol = await AssetsContractController.getERC721AssetSymbol(to);
} catch (e) {
tokenSymbol = 'ERC20 Token';
tokenDecimals = 18;
Expand Down
5 changes: 4 additions & 1 deletion app/components/UI/Swaps/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,10 @@ function SwapsAmountView({
setContractBalanceAsUnits(safeNumberToBN(0));
const { AssetsContractController } = Engine.context;
try {
const balance = await AssetsContractController.getBalanceOf(sourceToken.address, selectedAddress);
const balance = await AssetsContractController.getERC20BalanceOf(
sourceToken.address,
selectedAddress
);
setContractBalanceAsUnits(balance);
setContractBalance(renderFromTokenMinimalUnit(balance, sourceToken.decimals));
} catch (e) {
Expand Down
4 changes: 2 additions & 2 deletions app/components/UI/TransactionEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ class TransactionEditor extends PureComponent {
} = this.props;
const { selectedAddress } = this.props;
try {
const owner = await AssetsContractController.getOwnerOf(address, tokenId);
const owner = await AssetsContractController.getERC721OwnerOf(address, tokenId);
const isOwner = toLowerCaseEquals(owner, selectedAddress);
if (!isOwner) {
return strings('transaction.invalid_collectible_ownership');
Expand Down Expand Up @@ -632,7 +632,7 @@ class TransactionEditor extends PureComponent {
} else {
const { AssetsContractController } = Engine.context;
try {
contractBalanceForAddress = await AssetsContractController.getBalanceOf(
contractBalanceForAddress = await AssetsContractController.getERC20BalanceOf(
selectedAsset.address,
checksummedFrom
);
Expand Down
4 changes: 2 additions & 2 deletions app/components/Views/Send/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ class Send extends PureComponent {
const { AssetsContractController } = Engine.context;
const token = { address };
try {
const decimals = await AssetsContractController.getTokenDecimals(address);
const decimals = await AssetsContractController.getERC20TokenDecimals(address);
token.decimals = parseInt(String(decimals));
} catch (e) {
// Drop tx since we don't have any form to get decimals and send the correct tx
Expand All @@ -375,7 +375,7 @@ class Send extends PureComponent {
this.onCancel();
}
try {
token.symbol = await AssetsContractController.getAssetSymbol(address);
token.symbol = await AssetsContractController.getERC721AssetSymbol(address);
} catch (e) {
token.symbol = 'ERC20';
}
Expand Down
2 changes: 1 addition & 1 deletion app/components/Views/SendFlow/SendTo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ class SendFlow extends PureComponent {
const networkId = NetworkList[providerType].networkId;
if (networkId === 1) {
try {
const symbol = await AssetsContractController.getAssetSymbol(toSelectedAddress);
const symbol = await AssetsContractController.getERC721AssetSymbol(toSelectedAddress);
if (symbol) {
addressError = (
<Text>
Expand Down
17 changes: 7 additions & 10 deletions app/core/Engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,12 @@ class Engine {
{
onPreferencesStateChange: (listener) => preferencesController.subscribe(listener),
onNetworkStateChange: (listener) => networkController.subscribe(listener),
getAssetName: assetsContractController.getAssetName.bind(assetsContractController),
getAssetSymbol: assetsContractController.getAssetSymbol.bind(assetsContractController),
getCollectibleTokenURI:
assetsContractController.getCollectibleTokenURI.bind(assetsContractController),
getOwnerOf: assetsContractController.getOwnerOf.bind(assetsContractController),
balanceOfERC1155Collectible:
assetsContractController.balanceOfERC1155Collectible.bind(assetsContractController),
uriERC1155Collectible:
assetsContractController.uriERC1155Collectible.bind(assetsContractController),
getERC721AssetName: assetsContractController.getERC721AssetName.bind(assetsContractController),
getERC721AssetSymbol: assetsContractController.getERC721AssetSymbol.bind(assetsContractController),
getERC721TokenURI: assetsContractController.getERC721TokenURI.bind(assetsContractController),
getERC721OwnerOf: assetsContractController.getERC721OwnerOf.bind(assetsContractController),
getERC1155BalanceOf: assetsContractController.getERC1155BalanceOf.bind(assetsContractController),
getERC1155TokenURI: assetsContractController.getERC1155TokenURI.bind(assetsContractController),
},
{
useIPFSSubdomains: false,
Expand Down Expand Up @@ -214,7 +211,7 @@ class Engine {
{
onTokensStateChange: (listener) => tokensController.subscribe(listener),
getSelectedAddress: () => preferencesController.state.selectedAddress,
getBalanceOf: assetsContractController.getBalanceOf.bind(assetsContractController),
getERC20BalanceOf: assetsContractController.getERC20BalanceOf.bind(assetsContractController),
},
{ interval: 10000 }
),
Expand Down
2 changes: 1 addition & 1 deletion app/util/transactions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ export async function isCollectibleAddress(address, tokenId) {
const { AssetsContractController } = Engine.context;
// Hack to know if the address is a collectible smart contract
// for now this method is called from tx element so we have the respective 'tokenId'
const ownerOf = await AssetsContractController.getOwnerOf(address, tokenId);
const ownerOf = await AssetsContractController.getERC721OwnerOf(address, tokenId);
const isCollectibleAddress = ownerOf && ownerOf !== '0x';
CollectibleAddresses.cache[address] = isCollectibleAddress;
return isCollectibleAddress;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"dependencies": {
"@exodus/react-native-payments": "git+https://github.com/MetaMask/react-native-payments.git#dbc8cbbed570892d2fea5e3d183bf243e062c1e5",
"@metamask/contract-metadata": "^1.30.0",
"@metamask/controllers": "^22.0.0",
"@metamask/controllers": "25.1.0",
"@metamask/etherscan-link": "^2.0.0",
"@metamask/swaps-controller": "^6.3.0",
"@react-native-clipboard/clipboard": "^1.8.4",
Expand Down
Loading