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-08-31 19:23:47 +00:00
|
|
|
import { useNetwork } from "./useNetwork";
|
2021-07-21 22:08:46 +00:00
|
|
|
|
|
|
|
export function useToken() {
|
2021-08-31 19:23:47 +00:00
|
|
|
const { activeNetworkId } = useNetwork();
|
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 =>
|
2021-08-31 19:23:47 +00:00
|
|
|
tokens[activeNetworkId.value].allTokens.find(
|
2021-07-21 22:08:46 +00:00
|
|
|
token => String(token.key).toLowerCase() === String(key).toLowerCase()
|
|
|
|
);
|
|
|
|
|
2021-08-31 19:23:47 +00:00
|
|
|
const allATokensV2 = computed(() => atokensV2[activeNetworkId.value].allTokens);
|
2021-07-21 22:08:46 +00:00
|
|
|
|
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
|
|
|
};
|
|
|
|
}
|