mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 09:47:37 +00:00
Merge pull request #132 from cypherstack/testing-exchange
Testing exchange
This commit is contained in:
commit
2d8a1fb0c7
10 changed files with 150 additions and 42 deletions
|
@ -275,7 +275,7 @@ class _RestoreWalletViewState extends ConsumerState<RestoreWalletView> {
|
|||
// without using them
|
||||
await manager.recoverFromMnemonic(
|
||||
mnemonic: mnemonic,
|
||||
maxUnusedAddressGap: 20,
|
||||
maxUnusedAddressGap: widget.coin == Coin.firo ? 50 : 20,
|
||||
maxNumberOfIndexesToCheck: 1000,
|
||||
height: height,
|
||||
);
|
||||
|
|
|
@ -1319,6 +1319,12 @@ class _SendViewState extends ConsumerState<SendView> {
|
|||
cryptoAmountController
|
||||
.text) ??
|
||||
Decimal.zero,
|
||||
updateChosen: (String fee) {
|
||||
setState(() {
|
||||
_calculateFeesFuture =
|
||||
Future(() => fee);
|
||||
});
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
|
|
|
@ -32,10 +32,12 @@ class TransactionFeeSelectionSheet extends ConsumerStatefulWidget {
|
|||
Key? key,
|
||||
required this.walletId,
|
||||
required this.amount,
|
||||
required this.updateChosen,
|
||||
}) : super(key: key);
|
||||
|
||||
final String walletId;
|
||||
final Decimal amount;
|
||||
final Function updateChosen;
|
||||
|
||||
@override
|
||||
ConsumerState<TransactionFeeSelectionSheet> createState() =>
|
||||
|
@ -223,6 +225,10 @@ class _TransactionFeeSelectionSheetState
|
|||
ref.read(feeRateTypeStateProvider.state).state =
|
||||
FeeRateType.fast;
|
||||
}
|
||||
String? fee = getAmount(FeeRateType.fast);
|
||||
if (fee != null) {
|
||||
widget.updateChosen(fee);
|
||||
}
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: Container(
|
||||
|
@ -352,6 +358,10 @@ class _TransactionFeeSelectionSheetState
|
|||
ref.read(feeRateTypeStateProvider.state).state =
|
||||
FeeRateType.average;
|
||||
}
|
||||
String? fee = getAmount(FeeRateType.average);
|
||||
if (fee != null) {
|
||||
widget.updateChosen(fee);
|
||||
}
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: Container(
|
||||
|
@ -479,6 +489,11 @@ class _TransactionFeeSelectionSheetState
|
|||
ref.read(feeRateTypeStateProvider.state).state =
|
||||
FeeRateType.slow;
|
||||
}
|
||||
String? fee = getAmount(FeeRateType.slow);
|
||||
print("fee $fee");
|
||||
if (fee != null) {
|
||||
widget.updateChosen(fee);
|
||||
}
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
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
|
||||
await manager.recoverFromMnemonic(
|
||||
mnemonic: mnemonic,
|
||||
maxUnusedAddressGap: 20,
|
||||
maxUnusedAddressGap: manager.coin == Coin.firo ? 50 : 20,
|
||||
maxNumberOfIndexesToCheck: 1000,
|
||||
height: restoreHeight,
|
||||
);
|
||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:io';
|
|||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
|
||||
class StackFileSystem {
|
||||
Directory? rootPath;
|
||||
|
@ -14,6 +15,9 @@ class StackFileSystem {
|
|||
final bool isDesktop = !(Platform.isAndroid || Platform.isIOS);
|
||||
|
||||
Future<Directory> prepareStorage() async {
|
||||
if (Platform.isAndroid) {
|
||||
await Permission.storage.request();
|
||||
}
|
||||
rootPath = (await getApplicationDocumentsDirectory());
|
||||
debugPrint(rootPath!.absolute.toString());
|
||||
if (Platform.isAndroid) {
|
||||
|
@ -22,13 +26,13 @@ class StackFileSystem {
|
|||
debugPrint(rootPath!.absolute.toString());
|
||||
|
||||
Directory sampleFolder =
|
||||
Directory('${rootPath!.path}/Documents/Stack_backups');
|
||||
Directory('${rootPath!.path}Documents/Stack_backups');
|
||||
if (Platform.isIOS) {
|
||||
sampleFolder = Directory(rootPath!.path);
|
||||
}
|
||||
try {
|
||||
if (!sampleFolder.existsSync()) {
|
||||
sampleFolder.createSync();
|
||||
sampleFolder.createSync(recursive: true);
|
||||
}
|
||||
} catch (e, s) {
|
||||
debugPrint("$e $s");
|
||||
|
@ -65,8 +69,7 @@ class StackFileSystem {
|
|||
result = await FilePicker.platform.pickFiles(
|
||||
dialogTitle: "Load backup file",
|
||||
initialDirectory: startPath!.path,
|
||||
type: FileType.custom,
|
||||
allowedExtensions: ['bin'],
|
||||
type: FileType.any,
|
||||
allowCompression: false,
|
||||
lockParentWindow: true,
|
||||
);
|
||||
|
|
|
@ -35,7 +35,8 @@ class _RestoringWalletCardState extends ConsumerState<RestoringWalletCard> {
|
|||
case StackRestoringStatus.waiting:
|
||||
return SvgPicture.asset(
|
||||
Assets.svg.loader,
|
||||
color: Theme.of(context).extension<StackColors>()!.buttonBackSecondary,
|
||||
color:
|
||||
Theme.of(context).extension<StackColors>()!.buttonBackSecondary,
|
||||
);
|
||||
case StackRestoringStatus.restoring:
|
||||
return const LoadingIndicator();
|
||||
|
@ -95,7 +96,10 @@ class _RestoringWalletCardState extends ConsumerState<RestoringWalletCard> {
|
|||
|
||||
try {
|
||||
final mnemonicList = await manager.mnemonic;
|
||||
const maxUnusedAddressGap = 20;
|
||||
int maxUnusedAddressGap = 20;
|
||||
if (coin == Coin.firo) {
|
||||
maxUnusedAddressGap = 50;
|
||||
}
|
||||
const maxNumberOfIndexesToCheck = 1000;
|
||||
|
||||
if (mnemonicList.isEmpty) {
|
||||
|
@ -155,14 +159,17 @@ class _RestoringWalletCardState extends ConsumerState<RestoringWalletCard> {
|
|||
? Container(
|
||||
height: 20,
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).extension<StackColors>()!.buttonBackSecondary,
|
||||
color: Theme.of(context)
|
||||
.extension<StackColors>()!
|
||||
.buttonBackSecondary,
|
||||
borderRadius: BorderRadius.circular(
|
||||
1000,
|
||||
),
|
||||
),
|
||||
child: RawMaterialButton(
|
||||
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
splashColor: Theme.of(context).extension<StackColors>()!.highlight,
|
||||
splashColor:
|
||||
Theme.of(context).extension<StackColors>()!.highlight,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(
|
||||
1000,
|
||||
|
@ -187,7 +194,9 @@ class _RestoringWalletCardState extends ConsumerState<RestoringWalletCard> {
|
|||
child: Text(
|
||||
"Show recovery phrase",
|
||||
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 {
|
||||
if (!Platform.isLinux) Wakelock.enable();
|
||||
|
||||
const int maxUnusedAddressGap = 20;
|
||||
int maxUnusedAddressGap = 20;
|
||||
|
||||
const int maxNumberOfIndexesToCheck = 1000;
|
||||
|
||||
showDialog<dynamic>(
|
||||
|
@ -88,6 +89,13 @@ class _WalletNetworkSettingsViewState
|
|||
);
|
||||
|
||||
try {
|
||||
if (ref
|
||||
.read(walletsChangeNotifierProvider)
|
||||
.getManager(widget.walletId)
|
||||
.coin ==
|
||||
Coin.firo) {
|
||||
maxUnusedAddressGap = 50;
|
||||
}
|
||||
await ref
|
||||
.read(walletsChangeNotifierProvider)
|
||||
.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;
|
||||
coinsToSpend.insert(coinsToSpend.length, chosen);
|
||||
}
|
||||
|
@ -4514,36 +4515,61 @@ class FiroWallet extends CoinServiceAPI {
|
|||
Future<int> estimateJoinSplitFee(
|
||||
int spendAmount,
|
||||
) async {
|
||||
int fee;
|
||||
int size;
|
||||
|
||||
for (fee = 0;;) {
|
||||
int currentRequired = spendAmount;
|
||||
|
||||
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;
|
||||
var lelantusEntry = await _getLelantusEntry();
|
||||
final balance = await availableBalance;
|
||||
int spendAmount =
|
||||
(balance * Decimal.fromInt(Constants.satsPerCoin)).toBigInt().toInt();
|
||||
if (spendAmount == 0 || lelantusEntry.isEmpty) {
|
||||
return LelantusFeeData(0, 0, []).fee;
|
||||
}
|
||||
ReceivePort receivePort = await getIsolate({
|
||||
"function": "estimateJoinSplit",
|
||||
"spendAmount": spendAmount,
|
||||
"subtractFeeFromAmount": true,
|
||||
"lelantusEntries": lelantusEntry,
|
||||
"coin": coin,
|
||||
});
|
||||
|
||||
return fee;
|
||||
final message = await receivePort.first;
|
||||
if (message is String) {
|
||||
Logging.instance.log("this is a string", level: LogLevel.Error);
|
||||
stop(receivePort);
|
||||
throw Exception("_fetchMaxFee isolate failed");
|
||||
}
|
||||
stop(receivePort);
|
||||
Logging.instance.log('Closing estimateJoinSplit!', level: LogLevel.Info);
|
||||
return (message as LelantusFeeData).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
|
||||
Future<int> estimateFeeFor(int satoshiAmount, int feeRate) async {
|
||||
|
|
|
@ -1558,7 +1558,7 @@ class WowneroWallet extends CoinServiceAPI {
|
|||
"WW3iVcnoAY6K9zNdU4qmdvZELefx6xZz4PMpTwUifRkvMQckyadhSPYMVPJhBdYE8P9c27fg9RPmVaWNFx1cDaj61HnetqBiy",
|
||||
satoshiAmount: satoshiAmount,
|
||||
args: {"feeRate": feeRateType}))['fee'];
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
await Future.delayed(const Duration(milliseconds: 500));
|
||||
} catch (e, s) {
|
||||
aprox = -9999999999999999;
|
||||
}
|
||||
|
|
|
@ -3283,9 +3283,9 @@ void main() {
|
|||
"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 {
|
||||
|
|
Loading…
Reference in a new issue