mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-03-12 09:32:33 +00:00
update balance to be in sats + fix receive page options on wallet types
This commit is contained in:
parent
263044f39b
commit
d58c2ba683
5 changed files with 43 additions and 4 deletions
|
@ -3,6 +3,7 @@ import 'package:cw_core/crypto_amount_format.dart';
|
|||
|
||||
const bitcoinAmountLength = 8;
|
||||
const bitcoinAmountDivider = 100000000;
|
||||
const lightningAmountDivider = 1;
|
||||
final bitcoinAmountFormat = NumberFormat()
|
||||
..maximumFractionDigits = bitcoinAmountLength
|
||||
..minimumFractionDigits = 1;
|
||||
|
@ -24,3 +25,8 @@ int stringDoubleToBitcoinAmount(String amount) {
|
|||
|
||||
return result;
|
||||
}
|
||||
|
||||
String bitcoinAmountToLightningString({required int amount}) {
|
||||
String formattedAmount = bitcoinAmountFormat.format(cryptoAmountToDouble(amount: amount, divider: lightningAmountDivider));
|
||||
return formattedAmount.substring(0, formattedAmount.length - 2);
|
||||
}
|
||||
|
|
|
@ -24,10 +24,10 @@ class LightningBalance extends Balance {
|
|||
final int frozen;
|
||||
|
||||
@override
|
||||
String get formattedAvailableBalance => bitcoinAmountToString(amount: confirmed - frozen);
|
||||
String get formattedAvailableBalance => bitcoinAmountToLightningString(amount: confirmed);
|
||||
|
||||
@override
|
||||
String get formattedAdditionalBalance => bitcoinAmountToString(amount: unconfirmed);
|
||||
String get formattedAdditionalBalance => bitcoinAmountToLightningString(amount: unconfirmed);
|
||||
|
||||
@override
|
||||
String get formattedUnAvailableBalance {
|
||||
|
|
|
@ -169,8 +169,13 @@ class LightningWalletBase
|
|||
workingDir = "$workingDir/wallets/lightning/${walletInfo.name}/breez/";
|
||||
new Directory(workingDir).createSync(recursive: true);
|
||||
breezConfig = breezConfig.copyWith(workingDir: workingDir);
|
||||
|
||||
try {
|
||||
// disconnect if already connected
|
||||
await sdk.disconnect();
|
||||
} catch (_) {}
|
||||
|
||||
try {
|
||||
await sdk.connect(config: breezConfig, seed: seedBytes);
|
||||
} catch (e) {
|
||||
print("Error connecting to Breez: $e");
|
||||
|
|
18
lib/entities/lightning_receive_option.dart
Normal file
18
lib/entities/lightning_receive_option.dart
Normal file
|
@ -0,0 +1,18 @@
|
|||
enum LightningReceiveOption {
|
||||
lightningInvoice,
|
||||
lightningOnchain;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
String label = '';
|
||||
switch (this) {
|
||||
case LightningReceiveOption.lightningInvoice:
|
||||
label = 'Lightning via Invoice';
|
||||
break;
|
||||
case LightningReceiveOption.lightningOnchain:
|
||||
label = 'Lightning via BTC address';
|
||||
break;
|
||||
}
|
||||
return label;
|
||||
}
|
||||
}
|
|
@ -12,8 +12,18 @@ abstract class ReceiveOptionViewModelBase with Store {
|
|||
: selectedReceiveOption = initialPageOption ?? ReceivePageOption.mainnet,
|
||||
_options = [] {
|
||||
final walletType = _wallet.type;
|
||||
_options =
|
||||
walletType == WalletType.haven ? [ReceivePageOption.mainnet] : ReceivePageOption.values;
|
||||
|
||||
switch (walletType) {
|
||||
case WalletType.haven:
|
||||
_options = [ReceivePageOption.mainnet];
|
||||
break;
|
||||
case WalletType.lightning:
|
||||
_options = [ReceivePageOption.lightningInvoice, ReceivePageOption.lightningOnchain];
|
||||
break;
|
||||
default:
|
||||
_options = [ReceivePageOption.mainnet, ReceivePageOption.anonPayDonationLink, ReceivePageOption.anonPayInvoice];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
final WalletBase _wallet;
|
||||
|
|
Loading…
Reference in a new issue