assembly/composables/useToken.ts
Georges KABBOUCHI a54be3569c wip
2021-07-27 01:19:20 +03:00

30 lines
812 B
TypeScript

import { computed } from "@nuxtjs/composition-api";
import atokensV2 from "~/constant/atokensV2";
import tokens from "~/constant/tokens";
import { useBigNumber } from "./useBigNumber";
import { useWeb3 } from "./useWeb3";
export function useToken() {
const { networkName } = useWeb3();
const { toBN, times, minus, div, pow } = useBigNumber();
const getTokenByKey = key =>
tokens[networkName.value].allTokens.find(
token => String(token.key).toLowerCase() === String(key).toLowerCase()
);
const allATokensV2 = computed(() => atokensV2[networkName.value].allTokens);
function valInt(val, decimals) {
const num = toBN(val);
const multiplier = pow(10, decimals);
return times(num, multiplier).toFixed(0);
}
return {
getTokenByKey,
allATokensV2,
valInt
};
}