mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-11 13:14:32 +00:00
handle user added wallet contracts
This commit is contained in:
parent
a2ae9c6244
commit
be11b18eb8
2 changed files with 12 additions and 26 deletions
|
@ -70,8 +70,10 @@ class _AddTokenViewState extends ConsumerState<AddTokenView> {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> onNextPressed() async {
|
Future<void> onNextPressed() async {
|
||||||
final selectedTokens =
|
final selectedTokens = tokenEntities
|
||||||
tokenEntities.where((e) => e.selected).map((e) => e.token).toList();
|
.where((e) => e.selected)
|
||||||
|
.map((e) => e.token.address)
|
||||||
|
.toList();
|
||||||
|
|
||||||
final ethWallet = ref
|
final ethWallet = ref
|
||||||
.read(walletsChangeNotifierProvider)
|
.read(walletsChangeNotifierProvider)
|
||||||
|
|
|
@ -62,39 +62,23 @@ class EthereumWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
||||||
Timer? timer;
|
Timer? timer;
|
||||||
Timer? _networkAliveTimer;
|
Timer? _networkAliveTimer;
|
||||||
|
|
||||||
Future<void> addTokenContracts(List<EthContract> contracts) async {
|
Future<void> addTokenContracts(List<String> contractAddresses) async {
|
||||||
List<EthContract> updatedContracts = [];
|
final set = getWalletTokenContractAddresses().toSet();
|
||||||
for (final contract in contracts) {
|
set.addAll(contractAddresses);
|
||||||
final updatedWalletIds = contract.walletIds.toList();
|
await updateWalletTokenContractAddresses(set.toList());
|
||||||
if (!updatedWalletIds.contains(walletId)) {
|
|
||||||
updatedWalletIds.add(walletId);
|
|
||||||
updatedContracts.add(contract.copyWith(walletIds: updatedWalletIds));
|
|
||||||
} else {
|
|
||||||
updatedContracts.add(contract);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await db.putEthContracts(updatedContracts);
|
|
||||||
|
|
||||||
GlobalEventBus.instance.fire(
|
GlobalEventBus.instance.fire(
|
||||||
UpdatedInBackgroundEvent(
|
UpdatedInBackgroundEvent(
|
||||||
"$contracts updated/added for: $walletId $walletName",
|
"$contractAddresses updated/added for: $walletId $walletName",
|
||||||
walletId,
|
walletId,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> removeTokenContract(String contractAddress) async {
|
Future<void> removeTokenContract(String contractAddress) async {
|
||||||
final contract =
|
final set = getWalletTokenContractAddresses().toSet();
|
||||||
await db.getEthContracts().addressEqualTo(contractAddress).findFirst();
|
set.removeWhere((e) => e == contractAddress);
|
||||||
|
await updateWalletTokenContractAddresses(set.toList());
|
||||||
if (contract == null) {
|
|
||||||
return; // todo some error?
|
|
||||||
}
|
|
||||||
|
|
||||||
final updatedWalletIds = contract.walletIds.toList();
|
|
||||||
updatedWalletIds.removeWhere((e) => e == contractAddress);
|
|
||||||
|
|
||||||
await db.putEthContract(contract.copyWith(walletIds: updatedWalletIds));
|
|
||||||
|
|
||||||
GlobalEventBus.instance.fire(
|
GlobalEventBus.instance.fire(
|
||||||
UpdatedInBackgroundEvent(
|
UpdatedInBackgroundEvent(
|
||||||
|
|
Loading…
Reference in a new issue