Skip to content

Commit 5e385cd

Browse files
committed
xelis send all fee subtraction
1 parent 968c36a commit 5e385cd

File tree

2 files changed

+85
-64
lines changed

2 files changed

+85
-64
lines changed

lib/wallets/wallet/impl/xelis_wallet.dart

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -631,16 +631,23 @@ class XelisWallet extends LibXelisWallet {
631631
'Address cannot be empty.',
632632
); // in the future, support for multiple recipients will work.
633633

634+
// but for now, no
635+
// Validate recipients
636+
if (recipients.length != 1) {
637+
throw Exception("$runtimeType confirmSend requires 1 recipient");
638+
}
639+
634640
final asset = assetId ?? libXelis.xelisAsset;
635641

636642
// Calculate total send amount
637-
final totalSendAmount = recipients.fold<Amount>(
638-
Amount(
639-
rawValue: BigInt.zero,
640-
fractionDigits: cryptoCurrency.fractionDigits,
641-
),
642-
(sum, recipient) => sum + recipient.amount,
643-
);
643+
final totalSendAmount = recipients.first.amount;
644+
// final totalSendAmount = recipients.fold<Amount>(
645+
// Amount(
646+
// rawValue: BigInt.zero,
647+
// fractionDigits: cryptoCurrency.fractionDigits,
648+
// ),
649+
// (sum, recipient) => sum + recipient.amount,
650+
// );
644651

645652
// Check balance using raw method
646653
final xelBalance = await libXelis.getXelisBalanceRaw(wallet!);
@@ -658,24 +665,38 @@ class XelisWallet extends LibXelisWallet {
658665
assetId: asset,
659666
);
660667

661-
// Check if we have enough for both transfers and fee
662-
if (totalSendAmount + boostedFee > balance) {
663-
final requiredAmt = await libXelis.formatCoin(
664-
wallet!,
665-
atomicAmount: (totalSendAmount + boostedFee).raw,
666-
assetHash: asset,
668+
final isSendAll = xelBalance == totalSendAmount.raw;
669+
if (isSendAll) {
670+
txData = txData.copyWith(
671+
recipients: [
672+
TxRecipient(
673+
address: recipients.first.address,
674+
amount: recipients.first.amount - boostedFee,
675+
isChange: recipients.first.isChange,
676+
addressType: recipients.first.addressType,
677+
),
678+
],
667679
);
680+
} else {
681+
// Check if we have enough for both transfers and fee
682+
if (totalSendAmount + boostedFee > balance) {
683+
final requiredAmt = await libXelis.formatCoin(
684+
wallet!,
685+
atomicAmount: (totalSendAmount + boostedFee).raw,
686+
assetHash: asset,
687+
);
668688

669-
final availableAmt = await libXelis.formatCoin(
670-
wallet!,
671-
atomicAmount: xelBalance,
672-
assetHash: asset,
673-
);
689+
final availableAmt = await libXelis.formatCoin(
690+
wallet!,
691+
atomicAmount: xelBalance,
692+
assetHash: asset,
693+
);
674694

675-
throw Exception(
676-
"Insufficient balance to cover transfers and fees. "
677-
"Required: $requiredAmt, Available: $availableAmt",
678-
);
695+
throw Exception(
696+
"Insufficient balance to cover transfers and fees. "
697+
"Required: $requiredAmt, Available: $availableAmt",
698+
);
699+
}
679700
}
680701

681702
return txData.copyWith(

pubspec.lock

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -439,162 +439,162 @@ packages:
439439
dependency: "direct main"
440440
description:
441441
name: cs_monero
442-
sha256: f48495ed6744a47598b36eaf28adc1e9e55f0d4ea3c18fe42eda0d3d8f714206
442+
sha256: "7cfbcd25135a0710ad096678160d7668abed8979838165f06975adbe6bbec215"
443443
url: "https://pub.dev"
444444
source: hosted
445-
version: "1.0.0-pre.3"
445+
version: "1.1.1"
446446
cs_monero_flutter_libs:
447447
dependency: "direct main"
448448
description:
449449
name: cs_monero_flutter_libs
450-
sha256: ccfd2c80e3f283f447602ecc548c9922b526002928a0fa1d34f1d6d74f73952e
450+
sha256: "47d716adc7b668653e359df785702d1213245f2fab6efa930a70b87e4cba23ae"
451451
url: "https://pub.dev"
452452
source: hosted
453-
version: "1.0.0-pre.0"
453+
version: "1.1.1"
454454
cs_monero_flutter_libs_android:
455455
dependency: transitive
456456
description:
457457
name: cs_monero_flutter_libs_android
458-
sha256: "8a03a93b84a091a6c09be2a3504002885af5e3e8e316b2776544271e9509d352"
458+
sha256: "4b9d1117e63352d27bd0cb7115fc20d6212bd02a7e6ec3cd8ab2b37fddfb21eb"
459459
url: "https://pub.dev"
460460
source: hosted
461-
version: "1.0.0-pre"
461+
version: "1.1.0"
462462
cs_monero_flutter_libs_android_arm64_v8a:
463463
dependency: transitive
464464
description:
465465
name: cs_monero_flutter_libs_android_arm64_v8a
466-
sha256: a412c30e8f72aefc2671f2ed76b50fdb70fc9eaa697f8c7050e0ede941f5863e
466+
sha256: cbb8704dcc1d02581a820b99188c97acaa140eaefedee9ce7d17910e24e5530f
467467
url: "https://pub.dev"
468468
source: hosted
469-
version: "1.0.0-pre"
469+
version: "1.1.0"
470470
cs_monero_flutter_libs_android_armeabi_v7a:
471471
dependency: transitive
472472
description:
473473
name: cs_monero_flutter_libs_android_armeabi_v7a
474-
sha256: "2177af9a62ca9c2997f88af09d54c784dc1ee49a3540abe73c0271d25eb8dadb"
474+
sha256: dc276544b169553a8a63855beaa6c2cf8180af68fb335ab1b629f2fa9370e123
475475
url: "https://pub.dev"
476476
source: hosted
477-
version: "1.0.0-pre"
477+
version: "1.1.0"
478478
cs_monero_flutter_libs_android_x86_64:
479479
dependency: transitive
480480
description:
481481
name: cs_monero_flutter_libs_android_x86_64
482-
sha256: ac5e03624c86438bbe47c986dab5bfe1fb3060a0b4bdb5dd8eea09795a5fc2c8
482+
sha256: fb02563c07d3fb4804925ec66446e26389ca2d92659493b72a6cf106765fa321
483483
url: "https://pub.dev"
484484
source: hosted
485-
version: "1.0.0-pre"
485+
version: "1.1.0"
486486
cs_monero_flutter_libs_ios:
487487
dependency: transitive
488488
description:
489489
name: cs_monero_flutter_libs_ios
490-
sha256: ec2e5b9b3ae3100f390deeff6114ffe3259a0701fafdc0f1028996e0da78b17b
490+
sha256: "6fbe1590b0633f42c906dfada1db8e3ce4f8899eae8728a4bb9b696dc7fb5155"
491491
url: "https://pub.dev"
492492
source: hosted
493-
version: "1.0.0-pre.0"
493+
version: "1.1.1"
494494
cs_monero_flutter_libs_linux:
495495
dependency: transitive
496496
description:
497497
name: cs_monero_flutter_libs_linux
498-
sha256: "65651535e028211d4c535dac53fdfec940935f1037f0a01bfdf4f6cf8b904362"
498+
sha256: "394a58f4efefd3857f1f3da03f21e33f1c2ca5141936db7a843e77286ffaa89e"
499499
url: "https://pub.dev"
500500
source: hosted
501-
version: "1.0.0-pre"
501+
version: "1.1.0"
502502
cs_monero_flutter_libs_macos:
503503
dependency: transitive
504504
description:
505505
name: cs_monero_flutter_libs_macos
506-
sha256: "609586b4e4524452698b4877ff886ad9aafd721373cddebba45d9d8a63a8cfc9"
506+
sha256: e00616ab86a0ea18b3360dbae8d862b83fa450b1a83355647e34e8c64696a6c7
507507
url: "https://pub.dev"
508508
source: hosted
509-
version: "1.0.0-pre"
509+
version: "1.1.0"
510510
cs_monero_flutter_libs_platform_interface:
511511
dependency: transitive
512512
description:
513513
name: cs_monero_flutter_libs_platform_interface
514-
sha256: "9df4ced42f5746c85c008f504f70b39efd05aa409bb82eaf4b2058d8454e0bb7"
514+
sha256: "7c832ed033257b82e2c30f1fc764f68fa4e4a780d4836a4f94384aaf9cd44ee7"
515515
url: "https://pub.dev"
516516
source: hosted
517-
version: "1.0.0-pre"
517+
version: "1.0.0"
518518
cs_monero_flutter_libs_windows:
519519
dependency: transitive
520520
description:
521521
name: cs_monero_flutter_libs_windows
522-
sha256: "4294f62e40ba2f155c52fccfdbb12029ed5c856ea8a546aebb3ebc94bc856e43"
522+
sha256: de265ed544a4edb9e778e88b56ccee098a1ad38cd4c4536a985f05d3dde95a23
523523
url: "https://pub.dev"
524524
source: hosted
525-
version: "1.0.0-pre"
525+
version: "1.1.0"
526526
cs_salvium:
527527
dependency: "direct main"
528528
description:
529529
name: cs_salvium
530-
sha256: "838a2f21b0ad567f68a5294360c4c96727b722037ae7bfdc26651c99d6c26bd3"
530+
sha256: e040a407bb485b177130a86dd6cd817b8cea933bbfae149a73c57a681deaa4a5
531531
url: "https://pub.dev"
532532
source: hosted
533-
version: "1.2.1"
533+
version: "2.0.0"
534534
cs_salvium_flutter_libs:
535535
dependency: "direct main"
536536
description:
537537
name: cs_salvium_flutter_libs
538-
sha256: d1e49ed67632f77d863ad3eafc78db8867f155cf9decf156345ec75c92e0d026
538+
sha256: "2aea1bbb6e6b69ac0a8e4dace2efc50507a10651ad9bec862f6a5ccd06a76578"
539539
url: "https://pub.dev"
540540
source: hosted
541-
version: "1.0.4"
541+
version: "2.0.0"
542542
cs_salvium_flutter_libs_android:
543543
dependency: transitive
544544
description:
545545
name: cs_salvium_flutter_libs_android
546-
sha256: "63603fc4c94d609e13c8e8064c742ac628ef006d3af9990e2c585489bde9b96d"
546+
sha256: ad9537942f7c1416fbb3432cb154d641262bd18c56471c4f62dd1d2e7e23f125
547547
url: "https://pub.dev"
548548
source: hosted
549-
version: "1.0.0"
549+
version: "2.0.0"
550550
cs_salvium_flutter_libs_android_arm64_v8a:
551551
dependency: transitive
552552
description:
553553
name: cs_salvium_flutter_libs_android_arm64_v8a
554-
sha256: "5ced9fe6d71dd22f90865600b8dff1ed07ce480db6c9de1a8d56e63318000e97"
554+
sha256: "4c307cd3276c7aa2a461ebcfc726adf9b4d9427dbdbad120dbe50f54d3690b4e"
555555
url: "https://pub.dev"
556556
source: hosted
557-
version: "1.0.0"
557+
version: "2.0.0"
558558
cs_salvium_flutter_libs_android_armeabi_v7a:
559559
dependency: transitive
560560
description:
561561
name: cs_salvium_flutter_libs_android_armeabi_v7a
562-
sha256: "2fb718dff22918e72b138c191dbd887d8d241f03a34add11e8d699c48b657b47"
562+
sha256: "9491e0cdd4452c9c907e137acd2d08f76d33efc7a9d4b86fbfab69224bc9f473"
563563
url: "https://pub.dev"
564564
source: hosted
565-
version: "1.0.0"
565+
version: "2.0.0"
566566
cs_salvium_flutter_libs_android_x86_64:
567567
dependency: transitive
568568
description:
569569
name: cs_salvium_flutter_libs_android_x86_64
570-
sha256: "85134ab635a4dddec5735fdd8f3971a1c33e3aaa1c8aa88e54f0b3d5e0d0caab"
570+
sha256: "0b87ccd86bd9b0eeb659dade948d076cddf908d535fe803b769030da8ff406dc"
571571
url: "https://pub.dev"
572572
source: hosted
573-
version: "1.0.0"
573+
version: "2.0.0"
574574
cs_salvium_flutter_libs_ios:
575575
dependency: transitive
576576
description:
577577
name: cs_salvium_flutter_libs_ios
578-
sha256: "54d18fbac60c8a602e4d0f967ea7d02fab71bff3e032f9576e159229ce372534"
578+
sha256: "4dc2447255f1c8997b6d26e72577e30ceab7f4622620549dc9de9eb8dccac35c"
579579
url: "https://pub.dev"
580580
source: hosted
581-
version: "1.1.1"
581+
version: "2.0.0"
582582
cs_salvium_flutter_libs_linux:
583583
dependency: transitive
584584
description:
585585
name: cs_salvium_flutter_libs_linux
586-
sha256: "0cb2f545ea4aa45c819a0656540d022a9c73a43681e50f1d2a5e72eaf1bc500e"
586+
sha256: "8adc16e9d0fb8dc439475ddb2eaa4fcde8433fa2cb6e14ce814b1a40965eda5c"
587587
url: "https://pub.dev"
588588
source: hosted
589-
version: "1.0.2"
589+
version: "2.0.0"
590590
cs_salvium_flutter_libs_macos:
591591
dependency: transitive
592592
description:
593593
name: cs_salvium_flutter_libs_macos
594-
sha256: "9df0818299a5ddadd41eb4c94de2cd8e519d1e9f4aa6166657397200397f402f"
594+
sha256: "428e4eead3d507112cb6f0b70f69bc43430b3db60f0b4d731e0d6a6fab0b69bb"
595595
url: "https://pub.dev"
596596
source: hosted
597-
version: "1.0.0"
597+
version: "2.0.0"
598598
cs_salvium_flutter_libs_platform_interface:
599599
dependency: transitive
600600
description:
@@ -607,10 +607,10 @@ packages:
607607
dependency: transitive
608608
description:
609609
name: cs_salvium_flutter_libs_windows
610-
sha256: "824966223a32bfe4d99c634d3b8d81917806d06ad878007552597e2070c25a02"
610+
sha256: "934a1eeb95619df9e23eff13a6a6a356322297abfa6ab871283cdf665cc32c7f"
611611
url: "https://pub.dev"
612612
source: hosted
613-
version: "1.2.0"
613+
version: "2.0.0"
614614
csslib:
615615
dependency: transitive
616616
description:

0 commit comments

Comments
 (0)