mirror of https://github.com/certusone/oyster.git
feat: parse accounts
This commit is contained in:
parent
e597b40d22
commit
c7a9c0b79a
|
@ -4,6 +4,8 @@ import * as BufferLayout from 'buffer-layout'
|
|||
import {WORMHOLE_PROGRAM_ID} from "../utils/ids";
|
||||
import BN from "bn.js";
|
||||
import {ASSET_CHAIN, getAssetAmountInUSD, getAssetName, getAssetTokenSymbol} from "../utils/assets";
|
||||
import { useEthereum } from "../contexts";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
|
||||
const { useConnection } = contexts.Connection;
|
||||
|
||||
|
@ -13,8 +15,8 @@ interface ParsedData {
|
|||
parsedAssetAddress: string,
|
||||
parsedAccount: any,
|
||||
assetDecimals: number,
|
||||
tokenName: string,
|
||||
tokenSymbol: string,
|
||||
name: string,
|
||||
symbol: string,
|
||||
sourceAddress: string,
|
||||
targetAddress: string,
|
||||
amountInUSD: number,
|
||||
|
@ -22,6 +24,7 @@ interface ParsedData {
|
|||
|
||||
export const useLockedFundsAccounts = () => {
|
||||
const connection = useConnection();
|
||||
const { tokenMap: ethTokens } = useEthereum();
|
||||
|
||||
const [lockedSolanaAccounts, setLockedSolanaAccounts] = useState<ParsedData[]>([]);
|
||||
const [loading, setLoading] = useState<boolean>(true);
|
||||
|
@ -59,17 +62,21 @@ export const useLockedFundsAccounts = () => {
|
|||
const dec = new BN(10).pow(new BN(parsedAccount.assetDecimals));
|
||||
const rawAmount = new BN(parsedAccount.amount, 2, "le")
|
||||
const amount = rawAmount.div(dec).toNumber();
|
||||
const parsedAssetAddress: string = new Buffer(parsedAccount.assetAddress.slice(12)).toString("hex")
|
||||
const parsedAssetAddress: string = parsedAccount.assetChain === ASSET_CHAIN.Solana ?
|
||||
new PublicKey(parsedAccount.targetAddress).toString() :
|
||||
new Buffer(parsedAccount.assetAddress.slice(12)).toString("hex")
|
||||
const parsedData: ParsedData = {
|
||||
amount: amount,
|
||||
rawAmount: rawAmount.toString(),
|
||||
parsedAssetAddress: parsedAssetAddress,
|
||||
parsedAccount: parsedAccount,
|
||||
assetDecimals: parsedAccount.assetDecimals,
|
||||
sourceAddress: new Buffer(parsedAccount.sourceAddress.slice(12)).toString("hex"),
|
||||
targetAddress: new Buffer(parsedAccount.targetAddress.slice(12)).toString("hex"),
|
||||
tokenName: getAssetName(parsedAssetAddress, parsedAccount.assetChain),
|
||||
tokenSymbol: getAssetTokenSymbol(parsedAssetAddress, parsedAccount.assetChain),
|
||||
sourceAddress: new PublicKey(parsedAccount.sourceAddress).toString(),
|
||||
targetAddress: parsedAccount.toChain === ASSET_CHAIN.Solana ?
|
||||
new PublicKey(parsedAccount.targetAddress).toString()
|
||||
: new Buffer(parsedAccount.targetAddress.slice(12)).toString("hex"),
|
||||
name: getAssetName(parsedAssetAddress, parsedAccount.assetChain),
|
||||
symbol: getAssetTokenSymbol(parsedAssetAddress, parsedAccount.assetChain),
|
||||
amountInUSD: getAssetAmountInUSD(amount, parsedAssetAddress, parsedAccount.assetChain),
|
||||
};
|
||||
filteredParsedAccounts.push(parsedData)
|
||||
|
@ -92,4 +99,4 @@ export const useLockedFundsAccounts = () => {
|
|||
return acc + val.amountInUSD;
|
||||
}, 0)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -86,12 +86,13 @@ export const HomeView = () => {
|
|||
return lockedSolanaAccounts.map((acc, index) => {
|
||||
return {
|
||||
key: index.toString(),
|
||||
symbol: acc.tokenSymbol,
|
||||
name: acc.tokenName,
|
||||
symbol: acc.symbol,
|
||||
name: acc.name,
|
||||
amount: acc.amountInUSD,
|
||||
sourceAddress: acc.parsedAccount.assetChain === ASSET_CHAIN.Solana ?
|
||||
<ExplorerLink address={acc.sourceAddress} type={"address"} /> :
|
||||
<EtherscanLink address={acc.sourceAddress} type={"address"} />,
|
||||
assetAddress: acc.parsedAccount.assetChain === ASSET_CHAIN.Solana ?
|
||||
<ExplorerLink address={acc.parsedAssetAddress} type={"address"} /> :
|
||||
<EtherscanLink address={acc.parsedAssetAddress} type={"address"} />,
|
||||
sourceAddress: <ExplorerLink address={acc.sourceAddress} type={"address"} />,
|
||||
targetAddress: acc.parsedAccount.toChain === ASSET_CHAIN.Solana ?
|
||||
<ExplorerLink address={acc.targetAddress} type={"address"} /> :
|
||||
<EtherscanLink address={acc.targetAddress} type={"address"} />,
|
||||
|
@ -115,6 +116,11 @@ export const HomeView = () => {
|
|||
dataIndex: 'amount',
|
||||
key: 'amount',
|
||||
},
|
||||
{
|
||||
title: 'Asset Address',
|
||||
dataIndex: 'assetAddress',
|
||||
key: 'assetAddress',
|
||||
},
|
||||
{
|
||||
title: 'Source Address',
|
||||
dataIndex: 'sourceAddress',
|
||||
|
|
Loading…
Reference in New Issue