Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import '../../../wallets/isar/models/wallet_info.dart';
import '../../../wallets/wallet/impl/epiccash_wallet.dart';
import '../../../wallets/wallet/impl/monero_wallet.dart';
import '../../../wallets/wallet/impl/wownero_wallet.dart';
import '../../../wallets/wallet/intermediate/lib_monero_wallet.dart';
import '../../../wallets/wallet/intermediate/external_wallet.dart';
import '../../../wallets/wallet/impl/xelis_wallet.dart';
import '../../../wallets/wallet/supporting/epiccash_wallet_info_extension.dart';
import '../../../wallets/wallet/wallet.dart';
Expand Down Expand Up @@ -391,7 +391,7 @@ class _RestoreWalletViewState extends ConsumerState<RestoreWalletView> {

await wallet.recover(isRescan: false);

if (wallet is LibMoneroWallet) {
if (wallet is ExternalWallet) {
await wallet.exit();
}

Expand Down
4 changes: 2 additions & 2 deletions lib/pages/exchange_view/send_from_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import '../../wallets/crypto_currency/crypto_currency.dart';
import '../../wallets/isar/providers/wallet_info_provider.dart';
import '../../wallets/models/tx_data.dart';
import '../../wallets/wallet/impl/firo_wallet.dart';
import '../../wallets/wallet/intermediate/lib_monero_wallet.dart';
import '../../wallets/wallet/intermediate/external_wallet.dart';
import '../../widgets/background.dart';
import '../../widgets/conditional_parent.dart';
import '../../widgets/custom_buttons/app_bar_icon_button.dart';
Expand Down Expand Up @@ -277,7 +277,7 @@ class _SendFromCardState extends ConsumerState<SendFromCard> {
// access to this screen but this is needed to get past an error that
// would occur only to lead to another error which is why xmr/wow wallets
// don't have access to this screen currently
if (wallet is LibMoneroWallet) {
if (wallet is ExternalWallet) {
await wallet.init();
await wallet.open();
}
Expand Down
4 changes: 2 additions & 2 deletions lib/pages/pinpad_views/lock_screen_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import '../../utilities/show_loading.dart';
import '../../utilities/show_node_tor_settings_mismatch.dart';
import '../../utilities/text_styles.dart';
import '../../utilities/util.dart';
import '../../wallets/wallet/intermediate/lib_monero_wallet.dart';
import '../../wallets/wallet/intermediate/external_wallet.dart';
import '../../widgets/background.dart';
import '../../widgets/custom_buttons/app_bar_icon_button.dart';
import '../../widgets/custom_buttons/blue_text_button.dart';
Expand Down Expand Up @@ -119,7 +119,7 @@ class _LockscreenViewState extends ConsumerState<LockscreenView> {
}

final Future<void> loadFuture;
if (wallet is LibMoneroWallet) {
if (wallet is ExternalWallet) {
loadFuture =
wallet.init().then((value) async => await (wallet).open());
} else {
Expand Down
4 changes: 2 additions & 2 deletions lib/pages/wallets_view/sub_widgets/favorite_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import '../../../utilities/text_styles.dart';
import '../../../utilities/util.dart';
import '../../../wallets/crypto_currency/coins/firo.dart';
import '../../../wallets/isar/providers/wallet_info_provider.dart';
import '../../../wallets/wallet/intermediate/lib_monero_wallet.dart';
import '../../../wallets/wallet/intermediate/external_wallet.dart';
import '../../../widgets/coin_card.dart';
import '../../../widgets/conditional_parent.dart';
import '../../wallet_view/wallet_view.dart';
Expand Down Expand Up @@ -132,7 +132,7 @@ class _FavoriteCardState extends ConsumerState<FavoriteCard> {
}

final Future<void> loadFuture;
if (wallet is LibMoneroWallet) {
if (wallet is ExternalWallet) {
loadFuture =
wallet.init().then((value) async => await (wallet).open());
} else {
Expand Down
4 changes: 2 additions & 2 deletions lib/pages/wallets_view/sub_widgets/wallet_list_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import '../../../utilities/show_node_tor_settings_mismatch.dart';
import '../../../utilities/text_styles.dart';
import '../../../utilities/util.dart';
import '../../../wallets/crypto_currency/crypto_currency.dart';
import '../../../wallets/wallet/intermediate/lib_monero_wallet.dart';
import '../../../wallets/wallet/intermediate/external_wallet.dart';
import '../../../widgets/dialogs/tor_warning_dialog.dart';
import '../../../widgets/rounded_white_container.dart';
import '../../wallet_view/wallet_view.dart';
Expand Down Expand Up @@ -99,7 +99,7 @@ class WalletListItem extends ConsumerWidget {
}

final Future<void> loadFuture;
if (wallet is LibMoneroWallet) {
if (wallet is ExternalWallet) {
loadFuture =
wallet.init().then((value) async => await (wallet).open());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import '../../utilities/show_loading.dart';
import '../../utilities/show_node_tor_settings_mismatch.dart';
import '../../utilities/util.dart';
import '../../wallets/crypto_currency/crypto_currency.dart';
import '../../wallets/wallet/intermediate/lib_monero_wallet.dart';
import '../../wallets/wallet/intermediate/external_wallet.dart';
import '../../widgets/rounded_container.dart';
import '../../widgets/wallet_info_row/wallet_info_row.dart';
import 'wallet_view/desktop_wallet_view.dart';
Expand Down Expand Up @@ -101,7 +101,7 @@ class CoinWalletsTable extends ConsumerWidget {
}

final Future<void> loadFuture;
if (wallet is LibMoneroWallet) {
if (wallet is ExternalWallet) {
loadFuture = wallet
.init()
.then((value) async => await (wallet).open());
Expand Down
3 changes: 3 additions & 0 deletions lib/utilities/test_node_connection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,15 @@ Future<bool> testNodeConnection({
final daemon = xelis_sdk.DaemonClient(
endPoint: "${formData.host!}:${formData.port!}",
secureWebSocket: formData.useSSL ?? false,
timeout: 5000
);
daemon.connect();

final xelis_sdk.GetInfoResult networkInfo = await daemon.getInfo();
testPassed = networkInfo.height != null;

daemon.disconnect();

Logging.instance.i(
"Xelis testNodeConnection result: \"${networkInfo.toString()}\"",
);
Expand Down
82 changes: 19 additions & 63 deletions lib/wallets/wallet/impl/xelis_wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import 'dart:math';

import 'package:isar/isar.dart';
import 'package:mutex/mutex.dart';
import 'package:stack_wallet_backup/generate_password.dart';
import 'package:xelis_dart_sdk/xelis_dart_sdk.dart' as xelis_sdk;
import 'package:xelis_flutter/src/api/wallet.dart' as x_wallet;
import 'package:stack_wallet_backup/generate_password.dart';

import '../../../models/balance.dart';
import '../../../models/isar/models/blockchain_data/address.dart';
Expand All @@ -31,28 +31,6 @@ class XelisWallet extends LibXelisWallet {
@override
int get isarTransactionVersion => 2;

@override
Future<void> init({bool? isRestore}) async {
Logging.instance.d("Xelis: init");

if (isRestore == true) {
await _restoreWallet();
return await super.init();
}

final String? walletExists = await secureStorageInterface.read(
key: "${walletId}_wallet",
);

if (walletExists == null) {
await _createNewWallet();
}

await open();

return await super.init();
}

Future<void> _createNewWallet() async {
final String password = generatePassword();

Expand All @@ -61,39 +39,24 @@ class XelisWallet extends LibXelisWallet {
key: Wallet.mnemonicPassphraseKey(walletId: info.walletId),
value: password,
);

await secureStorageInterface.write(
key: '${walletId}_wallet',
value: 'true',
);

await secureStorageInterface.write(
key: '_${walletId}_needs_creation',
value: 'true',
);
}

Future<void> _restoreWallet() async {
final String password = generatePassword();

await secureStorageInterface.write(
key: Wallet.mnemonicPassphraseKey(walletId: info.walletId),
value: password,
);

await secureStorageInterface.write(
key: '${walletId}_wallet',
value: 'true',
);
@override
Future<void> init({bool? isRestore}) async {
Logging.instance.d("Xelis: init");

await secureStorageInterface.write(
key: '_${walletId}_needs_restoration',
value: 'true',
);
if (isRestore == true) {
await super.init();
return await open(openType: XelisWalletOpenType.restore);
}

if (libXelisWallet != null) {
await super.exit();
final bool walletExists = await LibXelisWallet.checkWalletExists(walletId);
if (!walletExists) {
await _createNewWallet();
await open(openType: XelisWalletOpenType.create);
}

return await super.init();
}

@override
Expand Down Expand Up @@ -507,20 +470,10 @@ class XelisWallet extends LibXelisWallet {
try {
checkInitialized();

// Use default address if recipients list is empty
final recipients =
txData.recipients?.isNotEmpty == true
? txData.recipients!
: [
(
address:
'xel:xz9574c80c4xegnvurazpmxhw5dlg2n0g9qm60uwgt75uqyx3pcsqzzra9m',
amount: Amount.zeroWith(
fractionDigits: cryptoCurrency.fractionDigits,
),
isChange: false,
),
];
: throw ArgumentError('Address cannot be empty.'); // in the future, support for multiple recipients will work.

final asset = assetId ?? xelis_sdk.xelisAsset;

Expand Down Expand Up @@ -596,7 +549,7 @@ class XelisWallet extends LibXelisWallet {
final defaultDecimals = cryptoCurrency.fractionDigits;
final defaultFee = BigInt.from(0);

// Use default address if recipients list is empty
// Use default address if recipients list is empty to ensure basic fee estimates are readily available
final effectiveRecipients =
recipients.isNotEmpty
? recipients
Expand Down Expand Up @@ -816,6 +769,9 @@ class XelisWallet extends LibXelisWallet {

@override
Future<void> handleOnline() async {
await updateChainHeight();
await updateBalance();
await updateTransactions();
GlobalEventBus.instance.fire(
WalletSyncStatusChangedEvent(
WalletSyncStatus.synced,
Expand Down
Loading
Loading