add nano support to AmountUnit

This commit is contained in:
julian 2023-05-30 09:32:17 -06:00
parent b49121acfe
commit 91d330e57b

View file

@ -26,6 +26,10 @@ enum AmountUnit {
pico(12), pico(12),
femto(15), femto(15),
atto(18), atto(18),
zepto(21),
yocto(24),
ronto(27),
quecto(30),
; ;
const AmountUnit(this.shift); const AmountUnit(this.shift);
@ -54,6 +58,9 @@ enum AmountUnit {
return AmountUnit.values.sublist(0, 5); return AmountUnit.values.sublist(0, 5);
case Coin.ethereum: case Coin.ethereum:
return AmountUnit.values.sublist(0, 7);
case Coin.nano:
return AmountUnit.values; return AmountUnit.values;
} }
} }
@ -71,7 +78,9 @@ extension AmountUnitExt on AmountUnit {
case AmountUnit.nano: case AmountUnit.nano:
if (coin == Coin.ethereum) { if (coin == Coin.ethereum) {
return "gwei"; return "gwei";
} else if (coin == Coin.wownero || coin == Coin.monero) { } else if (coin == Coin.wownero ||
coin == Coin.monero ||
coin == Coin.nano) {
return "n${coin.ticker}"; return "n${coin.ticker}";
} else { } else {
return "sats"; return "sats";
@ -79,7 +88,9 @@ extension AmountUnitExt on AmountUnit {
case AmountUnit.pico: case AmountUnit.pico:
if (coin == Coin.ethereum) { if (coin == Coin.ethereum) {
return "mwei"; return "mwei";
} else if (coin == Coin.wownero || coin == Coin.monero) { } else if (coin == Coin.wownero ||
coin == Coin.monero ||
coin == Coin.nano) {
return "p${coin.ticker}"; return "p${coin.ticker}";
} else { } else {
return "invalid"; return "invalid";
@ -87,12 +98,40 @@ extension AmountUnitExt on AmountUnit {
case AmountUnit.femto: case AmountUnit.femto:
if (coin == Coin.ethereum) { if (coin == Coin.ethereum) {
return "kwei"; return "kwei";
} else if (coin == Coin.nano) {
return "f${coin.ticker}";
} else { } else {
return "invalid"; return "invalid";
} }
case AmountUnit.atto: case AmountUnit.atto:
if (coin == Coin.ethereum) { if (coin == Coin.ethereum) {
return "wei"; return "wei";
} else if (coin == Coin.nano) {
return "a${coin.ticker}";
} else {
return "invalid";
}
case AmountUnit.zepto:
if (coin == Coin.nano) {
return "z${coin.ticker}";
} else {
return "invalid";
}
case AmountUnit.yocto:
if (coin == Coin.nano) {
return "y${coin.ticker}";
} else {
return "invalid";
}
case AmountUnit.ronto:
if (coin == Coin.nano) {
return "r${coin.ticker}";
} else {
return "invalid";
}
case AmountUnit.quecto:
if (coin == Coin.nano) {
return "q${coin.ticker}";
} else { } else {
return "invalid"; return "invalid";
} }
@ -115,6 +154,10 @@ extension AmountUnitExt on AmountUnit {
return "kwei"; return "kwei";
case AmountUnit.atto: case AmountUnit.atto:
return "wei"; return "wei";
default:
throw ArgumentError(
"Does eth even allow more than 18 decimal places?",
);
} }
} }