Move balance formatting to utils

This commit is contained in:
Alexis Sellier
2021-03-08 12:04:50 +01:00
parent cc75deb78b
commit 05c6623e63
3 changed files with 10 additions and 10 deletions
+1 -4
View File
@@ -3,6 +3,7 @@
// TODO: Link to correct network on etherscan
import { ethers } from "ethers";
import { link } from "svelte-routing";
import { formatBalance } from "@app/utils";
import { CONNECTION, session, connectWallet, disconnectWallet, shortAddress } from "./session.js";
import { error } from './error.js';
import Logo from './Logo.svelte';
@@ -10,10 +11,6 @@
let sessionButton = null;
let sessionButtonHover = false;
function formatBalance(balance) {
return ethers.utils.commify(ethers.utils.formatUnits(balance));
}
</script>
<style>
+4 -6
View File
@@ -1,4 +1,5 @@
import { ethers } from "ethers";
import { formatBalance } from "@app/utils";
import { STATE, state } from "./state.js";
const abi = [
@@ -49,12 +50,9 @@ export async function getInfo(address, config) {
token: token,
symbol: symbol,
beneficiary: beneficiary,
totalVesting: format(total),
withdrawableBalance: format(withdrawable),
withdrawn: format(withdrawn),
totalVesting: formatBalance(total),
withdrawableBalance: formatBalance(withdrawable),
withdrawn: formatBalance(withdrawn),
};
}
function format(n) {
return ethers.utils.commify(parseFloat(ethers.utils.formatUnits(n)).toFixed(2));
}
+5
View File
@@ -0,0 +1,5 @@
import { ethers } from "ethers";
export function formatBalance(n) {
return ethers.utils.commify(parseFloat(ethers.utils.formatUnits(n)).toFixed(2));
}