fix nullable type

Serhii committed Jan 20, 2023 at 23:18 UTC 912a4af86646328bd454a4f6f359de73b2a72fbe
1 file changed +16 -21
lib/view_model/wallet_address_list/wallet_address_edit_or_create_view_model.dart
+16 -21
@@ -99,27 +99,22 @@ abstract class WalletAddressEditOrCreateViewModelBase with Store {
99 await wallet.walletAddresses.updateAddress(_item.address as String);
100 await wallet.save();
101 }*/
102 -
103 - if (wallet.type == WalletType.monero) {
104 - await monero
105 - !.getSubaddressList(wallet)
106 - .setLabelSubaddress(
107 - wallet,
108 - accountIndex: monero!.getCurrentAccount(wallet).id,
109 - addressIndex: _item?.id as int,
110 - label: label);
111 - await wallet.save();
112 - }
113 -
114 - if (wallet.type == WalletType.haven) {
115 - await haven
116 - !.getSubaddressList(wallet)
117 - .setLabelSubaddress(
118 - wallet,
119 - accountIndex: haven!.getCurrentAccount(wallet).id,
120 - addressIndex: _item?.id as int,
121 - label: label);
122 - await wallet.save();
102 + final index = _item?.id;
103 + if (index != null) {
104 + if (wallet.type == WalletType.monero) {
105 + await monero!.getSubaddressList(wallet).setLabelSubaddress(wallet,
106 + accountIndex: monero!.getCurrentAccount(wallet).id, addressIndex: index, label: label);
107 + await wallet.save();
108 + return;
109 + }
110 + if (wallet.type == WalletType.haven) {
111 + await haven!.getSubaddressList(wallet).setLabelSubaddress(wallet,
112 + accountIndex: haven!.getCurrentAccount(wallet).id,
113 + addressIndex: _item?.id as int,
114 + label: label);
115 + await wallet.save();
116 + return;
117 + }
118 }
119 }
120 }