Skip to content

Commit

Permalink
fix Acala collateral withdraw issue
Browse files Browse the repository at this point in the history
  • Loading branch information
RomeroYang committed Aug 3, 2020
1 parent 905ae7b commit 5d1326d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
8 changes: 7 additions & 1 deletion lib/page-acala/loan/loanAdjustPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,19 @@ class _LoanAdjustPageState extends State<LoanAdjustPage> {
]
};
case LoanAdjustPage.actionTypeWithdraw:

/// withdraw all if user input near max
BigInt amt =
loan.collaterals - _amountCollateral > BigInt.parse('1000000000000')
? _amountCollateral
: loan.collaterals;
return {
'detail': jsonEncode({
"amount": _amountCtrl.text.trim(),
}),
'params': [
params.token,
(BigInt.zero - _amountCollateral).toString(),
(BigInt.zero - amt).toString(),
0,
]
};
Expand Down
12 changes: 8 additions & 4 deletions lib/utils/format.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,14 @@ class Fmt {
return BigInt.zero;
}
double v = 0;
if (value.contains(',') || value.contains('.')) {
v = NumberFormat(",##0.${"0" * decimals}").parse(value);
} else {
v = double.parse(value);
try {
if (value.contains(',') || value.contains('.')) {
v = NumberFormat(",##0.${"0" * decimals}").parse(value);
} else {
v = double.parse(value);
}
} catch (err) {
print('Fmt.tokenInt() error: ${err.toString()}');
}
return BigInt.from(v * pow(10, decimals));
}
Expand Down

0 comments on commit 5d1326d

Please sign in to comment.