mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-11-30 11:54:22 +01:00
CW-1175-Implement-swaps.xyz-swap-provider (#2526)
* Integrate SwapsXYZ * Remove print * enhance SwapsXyz EVM token swap handling * Disable fixed rate support in SwapsXyz provider * enable fixed rate swap * fix timestamp parsing * remove sender and recipient address from fetchRate * Improve SwapsXYZ trade approval logic * fix trade ID overflow * add Base chain support for swaps xyz * Update lib/view_model/exchange/exchange_trade_view_model.dart Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com> * add missing support for Base --------- Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
This commit is contained in:
@@ -71,4 +71,54 @@ class AmountConverter {
|
||||
|
||||
static String _moneroAmountToStringUsingDecimals(int amount) => _moneroAmountFormat.format(
|
||||
DecimalIntl(cryptoAmountToDecimal(amount: amount, divider: _moneroAmountDivider)));
|
||||
|
||||
|
||||
static String toBaseUnits(String amount, int decimals) {
|
||||
amount = amount.trim();
|
||||
if (amount.isEmpty) return '0';
|
||||
|
||||
final neg = amount.startsWith('-');
|
||||
if (neg) amount = amount.substring(1);
|
||||
|
||||
amount = amount.replaceAll(',', '');
|
||||
final parts = amount.split('.');
|
||||
final whole = parts[0].isEmpty ? '0' : parts[0];
|
||||
final frac = parts.length > 1 ? parts[1] : '';
|
||||
|
||||
final fracPadded = (frac + '0' * decimals).substring(0, decimals);
|
||||
|
||||
final pow10 = BigInt.from(10).pow(decimals);
|
||||
final wholeBI = BigInt.parse(whole);
|
||||
final fracBI = fracPadded.isEmpty ? BigInt.zero : BigInt.parse(fracPadded);
|
||||
|
||||
final res = wholeBI * pow10 + fracBI;
|
||||
return neg ? '-${res.toString()}' : res.toString();
|
||||
}
|
||||
|
||||
|
||||
static String fromBaseUnits(String units, int decimals) {
|
||||
units = units.trim();
|
||||
if (units.isEmpty) return '0';
|
||||
|
||||
final neg = units.startsWith('-');
|
||||
if (neg) units = units.substring(1);
|
||||
|
||||
if (decimals == 0) return neg ? '-$units' : units;
|
||||
|
||||
// pad if shorter than decimals
|
||||
if (units.length <= decimals) {
|
||||
final s = units.padLeft(decimals + 1, '0'); // ensures at least "0xxxx"
|
||||
final intPart = s.substring(0, s.length - decimals);
|
||||
var fracPart = s.substring(s.length - decimals);
|
||||
fracPart = fracPart.replaceFirst(RegExp(r'0+$'), '');
|
||||
final out = fracPart.isEmpty ? intPart : '$intPart.$fracPart';
|
||||
return neg ? '-$out' : out;
|
||||
}
|
||||
|
||||
final intPart = units.substring(0, units.length - decimals);
|
||||
var fracPart = units.substring(units.length - decimals);
|
||||
fracPart = fracPart.replaceFirst(RegExp(r'0+$'), '');
|
||||
final out = fracPart.isEmpty ? intPart : '$intPart.$fracPart';
|
||||
return neg ? '-$out' : out;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ mixin PendingTransaction {
|
||||
String get feeFormattedValue;
|
||||
String? feeRate;
|
||||
String get hex;
|
||||
String? get evmTxHashFromRawHex => null;
|
||||
int? get outputCount => null;
|
||||
PendingChange? change;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user