Explorer: remove wasm stake parsing (#13266)
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import React from "react";
|
||||
import { StakeAccount as StakeAccountWasm, Meta } from "solana-sdk-wasm";
|
||||
import { TableCardBody } from "components/common/TableCardBody";
|
||||
import { lamportsToSolString } from "utils";
|
||||
import { displayTimestamp } from "utils/date";
|
||||
@@ -22,7 +21,7 @@ export function StakeAccountSection({
|
||||
stakeAccountType,
|
||||
}: {
|
||||
account: Account;
|
||||
stakeAccount: StakeAccountInfo | StakeAccountWasm;
|
||||
stakeAccount: StakeAccountInfo;
|
||||
stakeAccountType: StakeAccountType;
|
||||
activation?: StakeActivationData;
|
||||
}) {
|
||||
@@ -48,11 +47,7 @@ export function StakeAccountSection({
|
||||
);
|
||||
}
|
||||
|
||||
function LockupCard({
|
||||
stakeAccount,
|
||||
}: {
|
||||
stakeAccount: StakeAccountInfo | StakeAccountWasm;
|
||||
}) {
|
||||
function LockupCard({ stakeAccount }: { stakeAccount: StakeAccountInfo }) {
|
||||
const unixTimestamp = stakeAccount.meta?.lockup.unixTimestamp;
|
||||
if (unixTimestamp && unixTimestamp > 0) {
|
||||
const prettyTimestamp = displayTimestamp(unixTimestamp * 1000);
|
||||
@@ -79,7 +74,7 @@ function OverviewCard({
|
||||
stakeAccountType,
|
||||
}: {
|
||||
account: Account;
|
||||
stakeAccount: StakeAccountInfo | StakeAccountWasm;
|
||||
stakeAccount: StakeAccountInfo;
|
||||
stakeAccountType: StakeAccountType;
|
||||
}) {
|
||||
const refresh = useFetchAccountInfo();
|
||||
@@ -135,7 +130,7 @@ function DelegationCard({
|
||||
stakeAccountType,
|
||||
activation,
|
||||
}: {
|
||||
stakeAccount: StakeAccountInfo | StakeAccountWasm;
|
||||
stakeAccount: StakeAccountInfo;
|
||||
stakeAccountType: StakeAccountType;
|
||||
activation?: StakeActivationData;
|
||||
}) {
|
||||
@@ -152,28 +147,15 @@ function DelegationCard({
|
||||
};
|
||||
|
||||
let voterPubkey, activationEpoch, deactivationEpoch;
|
||||
if ("accountType" in stakeAccount) {
|
||||
const delegation = stakeAccount?.stake?.delegation;
|
||||
if (delegation) {
|
||||
voterPubkey = delegation.voterPubkey;
|
||||
activationEpoch = delegation.isBootstrapStake()
|
||||
? "-"
|
||||
: delegation.activationEpoch;
|
||||
deactivationEpoch = delegation.isDeactivated()
|
||||
? delegation.deactivationEpoch
|
||||
: "-";
|
||||
}
|
||||
} else {
|
||||
const delegation = stakeAccount?.stake?.delegation;
|
||||
if (delegation) {
|
||||
voterPubkey = delegation.voter;
|
||||
activationEpoch = delegation.activationEpoch.eq(MAX_EPOCH)
|
||||
? "-"
|
||||
: delegation.activationEpoch.toString();
|
||||
deactivationEpoch = delegation.deactivationEpoch.eq(MAX_EPOCH)
|
||||
? "-"
|
||||
: delegation.deactivationEpoch.toString();
|
||||
}
|
||||
const delegation = stakeAccount?.stake?.delegation;
|
||||
if (delegation) {
|
||||
voterPubkey = delegation.voter;
|
||||
activationEpoch = delegation.activationEpoch.eq(MAX_EPOCH)
|
||||
? "-"
|
||||
: delegation.activationEpoch.toString();
|
||||
deactivationEpoch = delegation.deactivationEpoch.eq(MAX_EPOCH)
|
||||
? "-"
|
||||
: delegation.deactivationEpoch.toString();
|
||||
}
|
||||
|
||||
const { stake } = stakeAccount;
|
||||
@@ -242,7 +224,7 @@ function DelegationCard({
|
||||
);
|
||||
}
|
||||
|
||||
function AuthoritiesCard({ meta }: { meta: Meta | StakeMeta }) {
|
||||
function AuthoritiesCard({ meta }: { meta: StakeMeta }) {
|
||||
const hasLockup = meta && meta.lockup.unixTimestamp > 0;
|
||||
return (
|
||||
<div className="card">
|
||||
|
@@ -3,12 +3,11 @@ import { Link } from "react-router-dom";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { clusterPath } from "utils/url";
|
||||
import { displayAddress } from "utils/tx";
|
||||
import { Pubkey } from "solana-sdk-wasm";
|
||||
import { useCluster } from "providers/cluster";
|
||||
|
||||
type CopyState = "copy" | "copied";
|
||||
type Props = {
|
||||
pubkey: PublicKey | Pubkey;
|
||||
pubkey: PublicKey;
|
||||
alignRight?: boolean;
|
||||
link?: boolean;
|
||||
raw?: boolean;
|
||||
|
@@ -167,21 +167,12 @@ function InfoSection({ account }: { account: Account }) {
|
||||
const data = account?.details?.data;
|
||||
|
||||
if (data && data.program === "stake") {
|
||||
let stakeAccountType, stakeAccount;
|
||||
if ("accountType" in data.parsed) {
|
||||
stakeAccount = data.parsed;
|
||||
stakeAccountType = data.parsed.accountType as any;
|
||||
} else {
|
||||
stakeAccount = data.parsed.info;
|
||||
stakeAccountType = data.parsed.type;
|
||||
}
|
||||
|
||||
return (
|
||||
<StakeAccountSection
|
||||
account={account}
|
||||
stakeAccount={stakeAccount}
|
||||
stakeAccount={data.parsed.info}
|
||||
activation={data.activation}
|
||||
stakeAccountType={stakeAccountType}
|
||||
stakeAccountType={data.parsed.type}
|
||||
/>
|
||||
);
|
||||
} else if (data && data.program === "spl-token") {
|
||||
|
@@ -1,14 +1,8 @@
|
||||
import React from "react";
|
||||
import { StakeAccount as StakeAccountWasm } from "solana-sdk-wasm";
|
||||
import {
|
||||
PublicKey,
|
||||
Connection,
|
||||
StakeProgram,
|
||||
StakeActivationData,
|
||||
} from "@solana/web3.js";
|
||||
import { PublicKey, Connection, StakeActivationData } from "@solana/web3.js";
|
||||
import { useCluster, Cluster } from "../cluster";
|
||||
import { HistoryProvider } from "./history";
|
||||
import { TokensProvider, TOKEN_PROGRAM_ID } from "./tokens";
|
||||
import { TokensProvider } from "./tokens";
|
||||
import { coerce } from "superstruct";
|
||||
import { ParsedInfo } from "validators";
|
||||
import { StakeAccount } from "validators/accounts/stake";
|
||||
@@ -28,7 +22,7 @@ export { useAccountHistory } from "./history";
|
||||
|
||||
export type StakeProgramData = {
|
||||
program: "stake";
|
||||
parsed: StakeAccount | StakeAccountWasm;
|
||||
parsed: StakeAccount;
|
||||
activation?: StakeActivationData;
|
||||
};
|
||||
|
||||
@@ -137,52 +131,24 @@ async function fetchAccountInfo(
|
||||
}
|
||||
|
||||
let data: ProgramData | undefined;
|
||||
if (result.owner.equals(StakeProgram.programId)) {
|
||||
try {
|
||||
let parsed: StakeAccount | StakeAccountWasm;
|
||||
let isDelegated: boolean = false;
|
||||
if ("parsed" in result.data) {
|
||||
const info = coerce(result.data.parsed, ParsedInfo);
|
||||
parsed = coerce(info, StakeAccount);
|
||||
isDelegated = parsed.type === "delegated";
|
||||
} else {
|
||||
const wasm = await import("solana-sdk-wasm");
|
||||
parsed = wasm.StakeAccount.fromAccountData(result.data);
|
||||
isDelegated = (parsed.accountType as any) === "delegated";
|
||||
}
|
||||
|
||||
const activation = isDelegated
|
||||
? await connection.getStakeActivation(pubkey)
|
||||
: undefined;
|
||||
|
||||
data = {
|
||||
program: "stake",
|
||||
parsed,
|
||||
activation,
|
||||
};
|
||||
} catch (err) {
|
||||
reportError(err, { url, address: pubkey.toBase58() });
|
||||
// TODO store error state in Account info
|
||||
}
|
||||
} else if (
|
||||
"parsed" in result.data &&
|
||||
result.owner.equals(TOKEN_PROGRAM_ID)
|
||||
) {
|
||||
try {
|
||||
const info = coerce(result.data.parsed, ParsedInfo);
|
||||
const parsed = coerce(info, TokenAccount);
|
||||
data = {
|
||||
program: "spl-token",
|
||||
parsed,
|
||||
};
|
||||
} catch (err) {
|
||||
reportError(err, { url, address: pubkey.toBase58() });
|
||||
// TODO store error state in Account info
|
||||
}
|
||||
} else if ("parsed" in result.data) {
|
||||
if ("parsed" in result.data) {
|
||||
try {
|
||||
const info = coerce(result.data.parsed, ParsedInfo);
|
||||
switch (result.data.program) {
|
||||
case "stake": {
|
||||
const parsed = coerce(info, StakeAccount);
|
||||
const isDelegated = parsed.type === "delegated";
|
||||
const activation = isDelegated
|
||||
? await connection.getStakeActivation(pubkey)
|
||||
: undefined;
|
||||
|
||||
data = {
|
||||
program: result.data.program,
|
||||
parsed,
|
||||
activation,
|
||||
};
|
||||
break;
|
||||
}
|
||||
case "vote":
|
||||
data = {
|
||||
program: result.data.program,
|
||||
@@ -207,6 +173,13 @@ async function fetchAccountInfo(
|
||||
parsed: coerce(info, ConfigAccount),
|
||||
};
|
||||
break;
|
||||
|
||||
case "spl-token":
|
||||
data = {
|
||||
program: result.data.program,
|
||||
parsed: coerce(info, TokenAccount),
|
||||
};
|
||||
break;
|
||||
default:
|
||||
data = undefined;
|
||||
}
|
||||
|
Reference in New Issue
Block a user