assembly/composables/useToken.ts

30 lines
812 B
TypeScript
Raw Normal View History

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