2020-04-05 17:23:38 +08:00
|
|
|
import {
|
|
|
|
PublicKey,
|
|
|
|
SystemProgram,
|
|
|
|
StakeProgram,
|
|
|
|
VOTE_PROGRAM_ID,
|
|
|
|
BpfLoader,
|
|
|
|
SYSVAR_CLOCK_PUBKEY,
|
|
|
|
SYSVAR_RENT_PUBKEY,
|
|
|
|
SYSVAR_REWARDS_PUBKEY,
|
|
|
|
SYSVAR_STAKE_HISTORY_PUBKEY
|
|
|
|
} from "@solana/web3.js";
|
|
|
|
|
2020-03-16 15:17:51 +08:00
|
|
|
export function findGetParameter(parameterName: string): string | null {
|
|
|
|
let result = null,
|
|
|
|
tmp = [];
|
|
|
|
window.location.search
|
|
|
|
.substr(1)
|
|
|
|
.split("&")
|
|
|
|
.forEach(function(item) {
|
|
|
|
tmp = item.split("=");
|
2020-04-04 17:24:25 +08:00
|
|
|
if (tmp[0] === parameterName) {
|
|
|
|
if (tmp.length === 2) {
|
|
|
|
result = decodeURIComponent(tmp[1]);
|
|
|
|
} else if (tmp.length === 1) {
|
|
|
|
result = "";
|
|
|
|
}
|
|
|
|
}
|
2020-03-16 15:17:51 +08:00
|
|
|
});
|
|
|
|
return result;
|
|
|
|
}
|
2020-03-19 22:31:05 +08:00
|
|
|
|
2020-03-30 23:34:03 +08:00
|
|
|
export function findPathSegment(pathName: string): string | null {
|
|
|
|
const segments = window.location.pathname.substr(1).split("/");
|
|
|
|
if (segments.length < 2) return null;
|
|
|
|
|
|
|
|
// remove all but last two segments
|
|
|
|
segments.splice(0, segments.length - 2);
|
|
|
|
|
|
|
|
if (segments[0] === pathName) {
|
|
|
|
return segments[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-03-19 22:31:05 +08:00
|
|
|
export function assertUnreachable(x: never): never {
|
|
|
|
throw new Error("Unreachable!");
|
|
|
|
}
|
2020-04-05 17:23:38 +08:00
|
|
|
|
|
|
|
const PROGRAM_IDS = {
|
|
|
|
Budget1111111111111111111111111111111111111: "Budget Program",
|
|
|
|
Config1111111111111111111111111111111111111: "Config Program",
|
|
|
|
Exchange11111111111111111111111111111111111: "Exchange Program",
|
|
|
|
[StakeProgram.programId.toBase58()]: "Stake Program",
|
|
|
|
Storage111111111111111111111111111111111111: "Storage Program",
|
|
|
|
[SystemProgram.programId.toBase58()]: "System Program",
|
|
|
|
Vest111111111111111111111111111111111111111: "Vest Program",
|
|
|
|
[VOTE_PROGRAM_ID.toBase58()]: "Vote Program"
|
|
|
|
};
|
|
|
|
|
|
|
|
const LOADER_IDS = {
|
|
|
|
MoveLdr111111111111111111111111111111111111: "Move Loader",
|
|
|
|
NativeLoader1111111111111111111111111111111: "Native Loader",
|
|
|
|
[BpfLoader.programId.toBase58()]: "BPF Loader"
|
|
|
|
};
|
|
|
|
|
|
|
|
const SYSVAR_IDS = {
|
|
|
|
Sysvar1111111111111111111111111111111111111: "SYSVAR",
|
|
|
|
[SYSVAR_CLOCK_PUBKEY.toBase58()]: "SYSVAR_CLOCK",
|
|
|
|
SysvarEpochSchedu1e111111111111111111111111: "SYSVAR_EPOCH_SCHEDULE",
|
|
|
|
SysvarFees111111111111111111111111111111111: "SYSVAR_FEES",
|
|
|
|
SysvarRecentB1ockHashes11111111111111111111: "SYSVAR_RECENT_BLOCKHASHES",
|
|
|
|
[SYSVAR_RENT_PUBKEY.toBase58()]: "SYSVAR_RENT",
|
|
|
|
[SYSVAR_REWARDS_PUBKEY.toBase58()]: "SYSVAR_REWARDS",
|
|
|
|
SysvarS1otHashes111111111111111111111111111: "SYSVAR_SLOT_HASHES",
|
|
|
|
SysvarS1otHistory11111111111111111111111111: "SYSVAR_SLOT_HISTORY",
|
|
|
|
[SYSVAR_STAKE_HISTORY_PUBKEY.toBase58()]: "SYSVAR_STAKE_HISTORY"
|
|
|
|
};
|
|
|
|
|
|
|
|
export function displayAddress(pubkey: PublicKey): string {
|
|
|
|
const address = pubkey.toBase58();
|
|
|
|
return (
|
|
|
|
PROGRAM_IDS[address] ||
|
|
|
|
LOADER_IDS[address] ||
|
|
|
|
SYSVAR_IDS[address] ||
|
|
|
|
address
|
|
|
|
);
|
|
|
|
}
|