mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-02-04 12:16:31 +00:00
Merge branch 'staging' into desktop
This commit is contained in:
commit
5d3204fefd
10 changed files with 150 additions and 42 deletions
|
@ -275,7 +275,7 @@ class _RestoreWalletViewState extends ConsumerState<RestoreWalletView> {
|
||||||
// without using them
|
// without using them
|
||||||
await manager.recoverFromMnemonic(
|
await manager.recoverFromMnemonic(
|
||||||
mnemonic: mnemonic,
|
mnemonic: mnemonic,
|
||||||
maxUnusedAddressGap: 20,
|
maxUnusedAddressGap: widget.coin == Coin.firo ? 50 : 20,
|
||||||
maxNumberOfIndexesToCheck: 1000,
|
maxNumberOfIndexesToCheck: 1000,
|
||||||
height: height,
|
height: height,
|
||||||
);
|
);
|
||||||
|
|
|
@ -1319,6 +1319,12 @@ class _SendViewState extends ConsumerState<SendView> {
|
||||||
cryptoAmountController
|
cryptoAmountController
|
||||||
.text) ??
|
.text) ??
|
||||||
Decimal.zero,
|
Decimal.zero,
|
||||||
|
updateChosen: (String fee) {
|
||||||
|
setState(() {
|
||||||
|
_calculateFeesFuture =
|
||||||
|
Future(() => fee);
|
||||||
|
});
|
||||||
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
|
@ -32,10 +32,12 @@ class TransactionFeeSelectionSheet extends ConsumerStatefulWidget {
|
||||||
Key? key,
|
Key? key,
|
||||||
required this.walletId,
|
required this.walletId,
|
||||||
required this.amount,
|
required this.amount,
|
||||||
|
required this.updateChosen,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
final String walletId;
|
final String walletId;
|
||||||
final Decimal amount;
|
final Decimal amount;
|
||||||
|
final Function updateChosen;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
ConsumerState<TransactionFeeSelectionSheet> createState() =>
|
ConsumerState<TransactionFeeSelectionSheet> createState() =>
|
||||||
|
@ -223,6 +225,10 @@ class _TransactionFeeSelectionSheetState
|
||||||
ref.read(feeRateTypeStateProvider.state).state =
|
ref.read(feeRateTypeStateProvider.state).state =
|
||||||
FeeRateType.fast;
|
FeeRateType.fast;
|
||||||
}
|
}
|
||||||
|
String? fee = getAmount(FeeRateType.fast);
|
||||||
|
if (fee != null) {
|
||||||
|
widget.updateChosen(fee);
|
||||||
|
}
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
},
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
|
@ -352,6 +358,10 @@ class _TransactionFeeSelectionSheetState
|
||||||
ref.read(feeRateTypeStateProvider.state).state =
|
ref.read(feeRateTypeStateProvider.state).state =
|
||||||
FeeRateType.average;
|
FeeRateType.average;
|
||||||
}
|
}
|
||||||
|
String? fee = getAmount(FeeRateType.average);
|
||||||
|
if (fee != null) {
|
||||||
|
widget.updateChosen(fee);
|
||||||
|
}
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
},
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
|
@ -479,6 +489,11 @@ class _TransactionFeeSelectionSheetState
|
||||||
ref.read(feeRateTypeStateProvider.state).state =
|
ref.read(feeRateTypeStateProvider.state).state =
|
||||||
FeeRateType.slow;
|
FeeRateType.slow;
|
||||||
}
|
}
|
||||||
|
String? fee = getAmount(FeeRateType.slow);
|
||||||
|
print("fee $fee");
|
||||||
|
if (fee != null) {
|
||||||
|
widget.updateChosen(fee);
|
||||||
|
}
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
},
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
|
@ -608,4 +623,45 @@ class _TransactionFeeSelectionSheetState
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String? getAmount(FeeRateType feeRateType) {
|
||||||
|
try {
|
||||||
|
print(feeRateType);
|
||||||
|
var amount = Format.decimalAmountToSatoshis(this.amount);
|
||||||
|
print(amount);
|
||||||
|
print(ref.read(feeSheetSessionCacheProvider).fast);
|
||||||
|
print(ref.read(feeSheetSessionCacheProvider).average);
|
||||||
|
print(ref.read(feeSheetSessionCacheProvider).slow);
|
||||||
|
switch (feeRateType) {
|
||||||
|
case FeeRateType.fast:
|
||||||
|
if (ref.read(feeSheetSessionCacheProvider).fast[amount] != null) {
|
||||||
|
return (ref.read(feeSheetSessionCacheProvider).fast[amount]
|
||||||
|
as Decimal)
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
|
||||||
|
case FeeRateType.average:
|
||||||
|
if (ref.read(feeSheetSessionCacheProvider).average[amount] != null) {
|
||||||
|
return (ref.read(feeSheetSessionCacheProvider).average[amount]
|
||||||
|
as Decimal)
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
|
||||||
|
case FeeRateType.slow:
|
||||||
|
print(ref.read(feeSheetSessionCacheProvider).slow);
|
||||||
|
print(ref.read(feeSheetSessionCacheProvider).slow[amount]);
|
||||||
|
if (ref.read(feeSheetSessionCacheProvider).slow[amount] != null) {
|
||||||
|
return (ref.read(feeSheetSessionCacheProvider).slow[amount]
|
||||||
|
as Decimal)
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} catch (e, s) {
|
||||||
|
print("$e $s");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -402,7 +402,7 @@ abstract class SWB {
|
||||||
// without using them
|
// without using them
|
||||||
await manager.recoverFromMnemonic(
|
await manager.recoverFromMnemonic(
|
||||||
mnemonic: mnemonic,
|
mnemonic: mnemonic,
|
||||||
maxUnusedAddressGap: 20,
|
maxUnusedAddressGap: manager.coin == Coin.firo ? 50 : 20,
|
||||||
maxNumberOfIndexesToCheck: 1000,
|
maxNumberOfIndexesToCheck: 1000,
|
||||||
height: restoreHeight,
|
height: restoreHeight,
|
||||||
);
|
);
|
||||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:io';
|
||||||
import 'package:file_picker/file_picker.dart';
|
import 'package:file_picker/file_picker.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
import 'package:permission_handler/permission_handler.dart';
|
||||||
|
|
||||||
class StackFileSystem {
|
class StackFileSystem {
|
||||||
Directory? rootPath;
|
Directory? rootPath;
|
||||||
|
@ -14,6 +15,9 @@ class StackFileSystem {
|
||||||
final bool isDesktop = !(Platform.isAndroid || Platform.isIOS);
|
final bool isDesktop = !(Platform.isAndroid || Platform.isIOS);
|
||||||
|
|
||||||
Future<Directory> prepareStorage() async {
|
Future<Directory> prepareStorage() async {
|
||||||
|
if (Platform.isAndroid) {
|
||||||
|
await Permission.storage.request();
|
||||||
|
}
|
||||||
rootPath = (await getApplicationDocumentsDirectory());
|
rootPath = (await getApplicationDocumentsDirectory());
|
||||||
debugPrint(rootPath!.absolute.toString());
|
debugPrint(rootPath!.absolute.toString());
|
||||||
if (Platform.isAndroid) {
|
if (Platform.isAndroid) {
|
||||||
|
@ -22,13 +26,13 @@ class StackFileSystem {
|
||||||
debugPrint(rootPath!.absolute.toString());
|
debugPrint(rootPath!.absolute.toString());
|
||||||
|
|
||||||
Directory sampleFolder =
|
Directory sampleFolder =
|
||||||
Directory('${rootPath!.path}/Documents/Stack_backups');
|
Directory('${rootPath!.path}Documents/Stack_backups');
|
||||||
if (Platform.isIOS) {
|
if (Platform.isIOS) {
|
||||||
sampleFolder = Directory(rootPath!.path);
|
sampleFolder = Directory(rootPath!.path);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (!sampleFolder.existsSync()) {
|
if (!sampleFolder.existsSync()) {
|
||||||
sampleFolder.createSync();
|
sampleFolder.createSync(recursive: true);
|
||||||
}
|
}
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
debugPrint("$e $s");
|
debugPrint("$e $s");
|
||||||
|
@ -65,8 +69,7 @@ class StackFileSystem {
|
||||||
result = await FilePicker.platform.pickFiles(
|
result = await FilePicker.platform.pickFiles(
|
||||||
dialogTitle: "Load backup file",
|
dialogTitle: "Load backup file",
|
||||||
initialDirectory: startPath!.path,
|
initialDirectory: startPath!.path,
|
||||||
type: FileType.custom,
|
type: FileType.any,
|
||||||
allowedExtensions: ['bin'],
|
|
||||||
allowCompression: false,
|
allowCompression: false,
|
||||||
lockParentWindow: true,
|
lockParentWindow: true,
|
||||||
);
|
);
|
||||||
|
|
|
@ -35,7 +35,8 @@ class _RestoringWalletCardState extends ConsumerState<RestoringWalletCard> {
|
||||||
case StackRestoringStatus.waiting:
|
case StackRestoringStatus.waiting:
|
||||||
return SvgPicture.asset(
|
return SvgPicture.asset(
|
||||||
Assets.svg.loader,
|
Assets.svg.loader,
|
||||||
color: Theme.of(context).extension<StackColors>()!.buttonBackSecondary,
|
color:
|
||||||
|
Theme.of(context).extension<StackColors>()!.buttonBackSecondary,
|
||||||
);
|
);
|
||||||
case StackRestoringStatus.restoring:
|
case StackRestoringStatus.restoring:
|
||||||
return const LoadingIndicator();
|
return const LoadingIndicator();
|
||||||
|
@ -95,7 +96,10 @@ class _RestoringWalletCardState extends ConsumerState<RestoringWalletCard> {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final mnemonicList = await manager.mnemonic;
|
final mnemonicList = await manager.mnemonic;
|
||||||
const maxUnusedAddressGap = 20;
|
int maxUnusedAddressGap = 20;
|
||||||
|
if (coin == Coin.firo) {
|
||||||
|
maxUnusedAddressGap = 50;
|
||||||
|
}
|
||||||
const maxNumberOfIndexesToCheck = 1000;
|
const maxNumberOfIndexesToCheck = 1000;
|
||||||
|
|
||||||
if (mnemonicList.isEmpty) {
|
if (mnemonicList.isEmpty) {
|
||||||
|
@ -155,14 +159,17 @@ class _RestoringWalletCardState extends ConsumerState<RestoringWalletCard> {
|
||||||
? Container(
|
? Container(
|
||||||
height: 20,
|
height: 20,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Theme.of(context).extension<StackColors>()!.buttonBackSecondary,
|
color: Theme.of(context)
|
||||||
|
.extension<StackColors>()!
|
||||||
|
.buttonBackSecondary,
|
||||||
borderRadius: BorderRadius.circular(
|
borderRadius: BorderRadius.circular(
|
||||||
1000,
|
1000,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: RawMaterialButton(
|
child: RawMaterialButton(
|
||||||
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||||
splashColor: Theme.of(context).extension<StackColors>()!.highlight,
|
splashColor:
|
||||||
|
Theme.of(context).extension<StackColors>()!.highlight,
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.circular(
|
borderRadius: BorderRadius.circular(
|
||||||
1000,
|
1000,
|
||||||
|
@ -187,7 +194,9 @@ class _RestoringWalletCardState extends ConsumerState<RestoringWalletCard> {
|
||||||
child: Text(
|
child: Text(
|
||||||
"Show recovery phrase",
|
"Show recovery phrase",
|
||||||
style: STextStyles.infoSmall(context).copyWith(
|
style: STextStyles.infoSmall(context).copyWith(
|
||||||
color: Theme.of(context).extension<StackColors>()!.accentColorDark),
|
color: Theme.of(context)
|
||||||
|
.extension<StackColors>()!
|
||||||
|
.accentColorDark),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
@ -77,7 +77,8 @@ class _WalletNetworkSettingsViewState
|
||||||
Future<void> _attemptRescan() async {
|
Future<void> _attemptRescan() async {
|
||||||
if (!Platform.isLinux) Wakelock.enable();
|
if (!Platform.isLinux) Wakelock.enable();
|
||||||
|
|
||||||
const int maxUnusedAddressGap = 20;
|
int maxUnusedAddressGap = 20;
|
||||||
|
|
||||||
const int maxNumberOfIndexesToCheck = 1000;
|
const int maxNumberOfIndexesToCheck = 1000;
|
||||||
|
|
||||||
showDialog<dynamic>(
|
showDialog<dynamic>(
|
||||||
|
@ -88,6 +89,13 @@ class _WalletNetworkSettingsViewState
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (ref
|
||||||
|
.read(walletsChangeNotifierProvider)
|
||||||
|
.getManager(widget.walletId)
|
||||||
|
.coin ==
|
||||||
|
Coin.firo) {
|
||||||
|
maxUnusedAddressGap = 50;
|
||||||
|
}
|
||||||
await ref
|
await ref
|
||||||
.read(walletsChangeNotifierProvider)
|
.read(walletsChangeNotifierProvider)
|
||||||
.getManager(widget.walletId)
|
.getManager(widget.walletId)
|
||||||
|
|
|
@ -4493,6 +4493,7 @@ class FiroWallet extends CoinServiceAPI {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: investigate the bug here where chosen is null, conditions, given one mint
|
||||||
spendVal += chosen!.amount;
|
spendVal += chosen!.amount;
|
||||||
coinsToSpend.insert(coinsToSpend.length, chosen);
|
coinsToSpend.insert(coinsToSpend.length, chosen);
|
||||||
}
|
}
|
||||||
|
@ -4514,36 +4515,61 @@ class FiroWallet extends CoinServiceAPI {
|
||||||
Future<int> estimateJoinSplitFee(
|
Future<int> estimateJoinSplitFee(
|
||||||
int spendAmount,
|
int spendAmount,
|
||||||
) async {
|
) async {
|
||||||
int fee;
|
var lelantusEntry = await _getLelantusEntry();
|
||||||
int size;
|
final balance = await availableBalance;
|
||||||
|
int spendAmount =
|
||||||
for (fee = 0;;) {
|
(balance * Decimal.fromInt(Constants.satsPerCoin)).toBigInt().toInt();
|
||||||
int currentRequired = spendAmount;
|
if (spendAmount == 0 || lelantusEntry.isEmpty) {
|
||||||
|
return LelantusFeeData(0, 0, []).fee;
|
||||||
var map = await getCoinsToJoinSplit(currentRequired);
|
|
||||||
if (map is bool && !map) {
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
ReceivePort receivePort = await getIsolate({
|
||||||
|
"function": "estimateJoinSplit",
|
||||||
|
"spendAmount": spendAmount,
|
||||||
|
"subtractFeeFromAmount": true,
|
||||||
|
"lelantusEntries": lelantusEntry,
|
||||||
|
"coin": coin,
|
||||||
|
});
|
||||||
|
|
||||||
List<DartLelantusEntry> coinsToBeSpent =
|
final message = await receivePort.first;
|
||||||
map['coinsToSpend'] as List<DartLelantusEntry>;
|
if (message is String) {
|
||||||
|
Logging.instance.log("this is a string", level: LogLevel.Error);
|
||||||
// 1054 is constant part, mainly Schnorr and Range proofs, 2560 is for each sigma/aux data
|
stop(receivePort);
|
||||||
// 179 other parts of tx, assuming 1 utxo and 1 jmint
|
throw Exception("_fetchMaxFee isolate failed");
|
||||||
size = 1054 + 2560 * coinsToBeSpent.length + 180;
|
|
||||||
// uint64_t feeNeeded = GetMinimumFee(size, DEFAULT_TX_CONFIRM_TARGET);
|
|
||||||
int feeNeeded =
|
|
||||||
size; //TODO(Levon) temporary, use real estimation methods here
|
|
||||||
|
|
||||||
if (fee >= feeNeeded) {
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
stop(receivePort);
|
||||||
fee = feeNeeded;
|
Logging.instance.log('Closing estimateJoinSplit!', level: LogLevel.Info);
|
||||||
}
|
return (message as LelantusFeeData).fee;
|
||||||
|
|
||||||
return fee;
|
|
||||||
}
|
}
|
||||||
|
// int fee;
|
||||||
|
// int size;
|
||||||
|
//
|
||||||
|
// for (fee = 0;;) {
|
||||||
|
// int currentRequired = spendAmount;
|
||||||
|
//
|
||||||
|
// TODO: investigate the bug here
|
||||||
|
// var map = await getCoinsToJoinSplit(currentRequired);
|
||||||
|
// if (map is bool && !map) {
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// List<DartLelantusEntry> coinsToBeSpent =
|
||||||
|
// map['coinsToSpend'] as List<DartLelantusEntry>;
|
||||||
|
//
|
||||||
|
// // 1054 is constant part, mainly Schnorr and Range proofs, 2560 is for each sigma/aux data
|
||||||
|
// // 179 other parts of tx, assuming 1 utxo and 1 jmint
|
||||||
|
// size = 1054 + 2560 * coinsToBeSpent.length + 180;
|
||||||
|
// // uint64_t feeNeeded = GetMinimumFee(size, DEFAULT_TX_CONFIRM_TARGET);
|
||||||
|
// int feeNeeded =
|
||||||
|
// size; //TODO(Levon) temporary, use real estimation methods here
|
||||||
|
//
|
||||||
|
// if (fee >= feeNeeded) {
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// fee = feeNeeded;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return fee;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<int> estimateFeeFor(int satoshiAmount, int feeRate) async {
|
Future<int> estimateFeeFor(int satoshiAmount, int feeRate) async {
|
||||||
|
|
|
@ -1558,7 +1558,7 @@ class WowneroWallet extends CoinServiceAPI {
|
||||||
"WW3iVcnoAY6K9zNdU4qmdvZELefx6xZz4PMpTwUifRkvMQckyadhSPYMVPJhBdYE8P9c27fg9RPmVaWNFx1cDaj61HnetqBiy",
|
"WW3iVcnoAY6K9zNdU4qmdvZELefx6xZz4PMpTwUifRkvMQckyadhSPYMVPJhBdYE8P9c27fg9RPmVaWNFx1cDaj61HnetqBiy",
|
||||||
satoshiAmount: satoshiAmount,
|
satoshiAmount: satoshiAmount,
|
||||||
args: {"feeRate": feeRateType}))['fee'];
|
args: {"feeRate": feeRateType}))['fee'];
|
||||||
await Future.delayed(const Duration(milliseconds: 100));
|
await Future.delayed(const Duration(milliseconds: 500));
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
aprox = -9999999999999999;
|
aprox = -9999999999999999;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3283,9 +3283,9 @@ void main() {
|
||||||
"a5V5r6We6mNZzWJwGwEeRML3mEYLjvK39w",
|
"a5V5r6We6mNZzWJwGwEeRML3mEYLjvK39w",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
expect(await firo.maxFee, 1234); // ???
|
expect(await firo.maxFee, 0); // ???
|
||||||
|
|
||||||
expect(await firo.balanceMinusMaxFee, Decimal.parse("-0.00001234"));
|
expect(await firo.balanceMinusMaxFee, Decimal.parse("0"));
|
||||||
});
|
});
|
||||||
|
|
||||||
test("wallet balance minus maxfee - wallet balance is not zero", () async {
|
test("wallet balance minus maxfee - wallet balance is not zero", () async {
|
||||||
|
|
Loading…
Reference in a new issue