mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-03-23 15:48:53 +00:00
fix eth token abi endpoint and some logic clean up
This commit is contained in:
parent
d747347414
commit
0ac8885aa8
3 changed files with 50 additions and 94 deletions
|
@ -686,7 +686,7 @@ abstract class EthereumAPI {
|
||||||
try {
|
try {
|
||||||
final response = await client.get(
|
final response = await client.get(
|
||||||
url: Uri.parse(
|
url: Uri.parse(
|
||||||
"$stackBaseServer/abis?addrs=$contractAddress&verbose=true",
|
"$stackBaseServer/abis?addrs=$contractAddress",
|
||||||
),
|
),
|
||||||
proxyInfo: Prefs.instance.useTor
|
proxyInfo: Prefs.instance.useTor
|
||||||
? TorService.sharedInstance.getProxyInfo()
|
? TorService.sharedInstance.getProxyInfo()
|
||||||
|
|
|
@ -92,16 +92,8 @@ class EthTokenWallet extends Wallet {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// String? mnemonicString = await ethWallet.getMnemonic();
|
|
||||||
//
|
|
||||||
// //Get private key for given mnemonic
|
|
||||||
// String privateKey = getPrivateKey(
|
|
||||||
// mnemonicString,
|
|
||||||
// (await ethWallet.getMnemonicPassphrase()),
|
|
||||||
// );
|
|
||||||
// _credentials = web3dart.EthPrivateKey.fromHex(privateKey);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// try parse abi and extract transfer function
|
||||||
_deployedContract = web3dart.DeployedContract(
|
_deployedContract = web3dart.DeployedContract(
|
||||||
ContractAbiExtensions.fromJsonList(
|
ContractAbiExtensions.fromJsonList(
|
||||||
jsonList: tokenContract.abi!,
|
jsonList: tokenContract.abi!,
|
||||||
|
@ -109,62 +101,27 @@ class EthTokenWallet extends Wallet {
|
||||||
),
|
),
|
||||||
contractAddress,
|
contractAddress,
|
||||||
);
|
);
|
||||||
} catch (_) {
|
|
||||||
rethrow;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
_sendFunction = _deployedContract.function('transfer');
|
_sendFunction = _deployedContract.function('transfer');
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
//====================================================================
|
// some failure so first try to make sure we have the latest abi
|
||||||
// final list = List<Map<String, dynamic>>.from(
|
_tokenContract = await _updateTokenABI(
|
||||||
// jsonDecode(tokenContract.abi!) as List);
|
forContract: tokenContract,
|
||||||
// final functionNames = list.map((e) => e["name"] as String);
|
usingContractAddress: contractAddress.hex,
|
||||||
//
|
);
|
||||||
// if (!functionNames.contains("balanceOf")) {
|
|
||||||
// list.add(
|
|
||||||
// {
|
|
||||||
// "encoding": "0x70a08231",
|
|
||||||
// "inputs": [
|
|
||||||
// {"name": "account", "type": "address"}
|
|
||||||
// ],
|
|
||||||
// "name": "balanceOf",
|
|
||||||
// "outputs": [
|
|
||||||
// {"name": "val_0", "type": "uint256"}
|
|
||||||
// ],
|
|
||||||
// "signature": "balanceOf(address)",
|
|
||||||
// "type": "function"
|
|
||||||
// },
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (!functionNames.contains("transfer")) {
|
|
||||||
// list.add(
|
|
||||||
// {
|
|
||||||
// "encoding": "0xa9059cbb",
|
|
||||||
// "inputs": [
|
|
||||||
// {"name": "dst", "type": "address"},
|
|
||||||
// {"name": "rawAmount", "type": "uint256"}
|
|
||||||
// ],
|
|
||||||
// "name": "transfer",
|
|
||||||
// "outputs": [
|
|
||||||
// {"name": "val_0", "type": "bool"}
|
|
||||||
// ],
|
|
||||||
// "signature": "transfer(address,uint256)",
|
|
||||||
// "type": "function"
|
|
||||||
// },
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
//--------------------------------------------------------------------
|
|
||||||
//====================================================================
|
|
||||||
|
|
||||||
// function not found so likely a proxy so we need to fetch the impl
|
try {
|
||||||
//====================================================================
|
// try again to parse abi and extract transfer function
|
||||||
// final updatedToken = tokenContract.copyWith(abi: jsonEncode(list));
|
_deployedContract = web3dart.DeployedContract(
|
||||||
// // Store updated contract
|
ContractAbiExtensions.fromJsonList(
|
||||||
// final id = await MainDB.instance.putEthContract(updatedToken);
|
jsonList: tokenContract.abi!,
|
||||||
// _tokenContract = updatedToken..id = id;
|
name: tokenContract.name,
|
||||||
//--------------------------------------------------------------------
|
),
|
||||||
|
contractAddress,
|
||||||
|
);
|
||||||
|
_sendFunction = _deployedContract.function('transfer');
|
||||||
|
} catch (_) {
|
||||||
|
// if it fails again we check if there is a proxy token impl and
|
||||||
|
// then try one last time to update and parse the abi
|
||||||
final contractAddressResponse =
|
final contractAddressResponse =
|
||||||
await EthereumAPI.getProxyTokenImplementationAddress(
|
await EthereumAPI.getProxyTokenImplementationAddress(
|
||||||
contractAddress.hex);
|
contractAddress.hex);
|
||||||
|
@ -177,10 +134,7 @@ class EthTokenWallet extends Wallet {
|
||||||
} else {
|
} else {
|
||||||
throw contractAddressResponse.exception!;
|
throw contractAddressResponse.exception!;
|
||||||
}
|
}
|
||||||
//====================================================================
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
_deployedContract = web3dart.DeployedContract(
|
_deployedContract = web3dart.DeployedContract(
|
||||||
ContractAbiExtensions.fromJsonList(
|
ContractAbiExtensions.fromJsonList(
|
||||||
jsonList: tokenContract.abi!,
|
jsonList: tokenContract.abi!,
|
||||||
|
@ -188,11 +142,10 @@ class EthTokenWallet extends Wallet {
|
||||||
),
|
),
|
||||||
contractAddress,
|
contractAddress,
|
||||||
);
|
);
|
||||||
} catch (_) {
|
|
||||||
rethrow;
|
|
||||||
}
|
|
||||||
|
|
||||||
_sendFunction = _deployedContract.function('transfer');
|
_sendFunction = _deployedContract.function('transfer');
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
Logging.instance.log(
|
Logging.instance.log(
|
||||||
"$runtimeType wallet failed init(): $e\n$s",
|
"$runtimeType wallet failed init(): $e\n$s",
|
||||||
|
|
|
@ -22,10 +22,10 @@ import 'package:stackwallet/wallets/isar/providers/wallet_info_provider.dart';
|
||||||
|
|
||||||
class WalletInfoRowBalance extends ConsumerWidget {
|
class WalletInfoRowBalance extends ConsumerWidget {
|
||||||
const WalletInfoRowBalance({
|
const WalletInfoRowBalance({
|
||||||
Key? key,
|
super.key,
|
||||||
required this.walletId,
|
required this.walletId,
|
||||||
this.contractAddress,
|
this.contractAddress,
|
||||||
}) : super(key: key);
|
});
|
||||||
|
|
||||||
final String walletId;
|
final String walletId;
|
||||||
final String? contractAddress;
|
final String? contractAddress;
|
||||||
|
@ -45,8 +45,11 @@ class WalletInfoRowBalance extends ConsumerWidget {
|
||||||
} else {
|
} else {
|
||||||
contract = MainDB.instance.getEthContractSync(contractAddress!)!;
|
contract = MainDB.instance.getEthContractSync(contractAddress!)!;
|
||||||
totalBalance = ref
|
totalBalance = ref
|
||||||
.watch(pTokenBalance(
|
.watch(
|
||||||
(contractAddress: contractAddress!, walletId: walletId)))
|
pTokenBalance(
|
||||||
|
(walletId: walletId, contractAddress: contractAddress!),
|
||||||
|
),
|
||||||
|
)
|
||||||
.total;
|
.total;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue