-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new EthConversions class
- Loading branch information
Yii
committed
Apr 20, 2022
1 parent
f3a9e12
commit 9470c92
Showing
4 changed files
with
57 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import 'dart:math'; | ||
|
||
class EthConversions { | ||
static double weiToEth(BigInt amount, int? decimal) { | ||
if (decimal == null) { | ||
double db = amount / BigInt.from(10).pow(18); | ||
return double.parse(db.toStringAsFixed(2)); | ||
} else { | ||
double db = amount / BigInt.from(10).pow(decimal); | ||
return double.parse(db.toStringAsFixed(2)); | ||
} | ||
} | ||
|
||
static double weiToEthUnTrimmed(BigInt amount, int? decimal) { | ||
if (decimal == null) { | ||
double db = amount / BigInt.from(10).pow(18); | ||
return double.parse(db.toStringAsFixed(6)); | ||
} else { | ||
double db = amount / BigInt.from(10).pow(decimal); | ||
return double.parse(db.toStringAsFixed(6)); | ||
} | ||
} | ||
|
||
static String weiToGwei(BigInt amount) { | ||
var db = amount / BigInt.from(10).pow(9); | ||
return db.toStringAsPrecision(2); | ||
} | ||
|
||
static BigInt ethToWei(String amount, int? decimal) { | ||
double db = double.parse(amount) * pow(10, 4); | ||
int it = db.toInt(); | ||
BigInt bi = BigInt.from(it) * | ||
BigInt.from(10).pow(decimal == null ? 14 : decimal - 4); | ||
return bi; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters