added enum to chain types

This commit is contained in:
juan 2021-03-03 16:12:35 -05:00
parent 287a2cadcf
commit bc75c4e023
3 changed files with 12 additions and 6 deletions

View File

@ -3,7 +3,7 @@ import {contexts} from "@oyster/common";
import * as BufferLayout from 'buffer-layout' import * as BufferLayout from 'buffer-layout'
import {WORMHOLE_PROGRAM_ID} from "../utils/ids"; import {WORMHOLE_PROGRAM_ID} from "../utils/ids";
import BN from "bn.js"; import BN from "bn.js";
import {getAssetAmountInUSD, getAssetName, getAssetTokenSymbol} from "../utils/assets"; import {ASSET_CHAIN, getAssetAmountInUSD, getAssetName, getAssetTokenSymbol} from "../utils/assets";
const { useConnection } = contexts.Connection; const { useConnection } = contexts.Connection;
@ -53,9 +53,9 @@ export const useLockedFundsAccounts = () => {
programAccounts.map(acc => { programAccounts.map(acc => {
try { try {
const parsedAccount = dataLayout.decode(acc.account.data) const parsedAccount = dataLayout.decode(acc.account.data)
const chains = [ASSET_CHAIN.Solana, ASSET_CHAIN.Ethereum]
if ((parsedAccount.assetChain === 1 || parsedAccount.assetChain ===2 ) && if (chains.indexOf(parsedAccount.assetChain) >= 0 &&
(parsedAccount.toChain === 1 || parsedAccount.toChain === 2)) { chains.indexOf(parsedAccount.toChain) >= 0) {
const dec = new BN(10).pow(new BN(parsedAccount.assetDecimals)); const dec = new BN(10).pow(new BN(parsedAccount.assetDecimals));
const rawAmount = new BN(parsedAccount.amount, 2, "le") const rawAmount = new BN(parsedAccount.amount, 2, "le")
const amount = rawAmount.div(dec).toNumber(); const amount = rawAmount.div(dec).toNumber();

View File

@ -19,3 +19,8 @@ export const getAssetAmountInUSD = (
) => { ) => {
return amount; return amount;
}; };
export enum ASSET_CHAIN {
Solana = 1,
Ethereum = 2,
}

View File

@ -11,6 +11,7 @@ import { Totals } from '../../models/totals';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import {useLockedFundsAccounts} from "../../hooks/useLockedFundsAccounts"; import {useLockedFundsAccounts} from "../../hooks/useLockedFundsAccounts";
import {EtherscanLink} from "@oyster/common/dist/lib/components/EtherscanLink"; import {EtherscanLink} from "@oyster/common/dist/lib/components/EtherscanLink";
import {ASSET_CHAIN} from "../../utils/assets";
const { fromLamports, getTokenName, wadToLamports } = utils; const { fromLamports, getTokenName, wadToLamports } = utils;
const { cache } = contexts.Accounts; const { cache } = contexts.Accounts;
const { useConnectionConfig } = contexts.Connection; const { useConnectionConfig } = contexts.Connection;
@ -87,10 +88,10 @@ export const HomeView = () => {
symbol: acc.tokenSymbol, symbol: acc.tokenSymbol,
name: acc.tokenName, name: acc.tokenName,
amount: acc.amountInUSD, amount: acc.amountInUSD,
sourceAddress: acc.parsedAccount.assetChain === 1 ? sourceAddress: acc.parsedAccount.assetChain === ASSET_CHAIN.Solana ?
<ExplorerLink address={acc.sourceAddress} type={"address"} /> : <ExplorerLink address={acc.sourceAddress} type={"address"} /> :
<EtherscanLink address={acc.sourceAddress} type={"address"} />, <EtherscanLink address={acc.sourceAddress} type={"address"} />,
targetAddress: acc.parsedAccount.toChain === 1 ? targetAddress: acc.parsedAccount.toChain === ASSET_CHAIN.Solana ?
<ExplorerLink address={acc.targetAddress} type={"address"} /> : <ExplorerLink address={acc.targetAddress} type={"address"} /> :
<EtherscanLink address={acc.targetAddress} type={"address"} />, <EtherscanLink address={acc.targetAddress} type={"address"} />,
} }