multisig-ui/src/store/reducer.ts

106 lines
2.4 KiB
TypeScript
Raw Normal View History

2021-04-22 22:05:29 -07:00
import { PublicKey } from "@solana/web3.js";
2021-04-22 12:16:15 -07:00
export type Action = {
type: ActionType;
item: any;
};
export enum ActionType {
CommonTriggerShutdown,
CommonDidShutdown,
CommonWalletDidConnect,
CommonWalletDidDisconnect,
CommonWalletSetProvider,
2021-04-22 22:05:29 -07:00
CommonSetNetwork,
2021-04-22 12:16:15 -07:00
}
export default function reducer(
state: State = initialState,
2021-04-22 22:05:29 -07:00
action: Action
2021-04-22 12:16:15 -07:00
): State {
let newState = {
common: { ...state.common },
};
switch (action.type) {
case ActionType.CommonWalletSetProvider:
newState.common.walletProvider = action.item.walletProvider;
return newState;
case ActionType.CommonWalletDidConnect:
newState.common.isWalletConnected = true;
return newState;
case ActionType.CommonWalletDidDisconnect:
newState.common.isWalletConnected = false;
return newState;
case ActionType.CommonSetNetwork:
if (newState.common.network.label !== action.item.network.label) {
newState.common.network = action.item.network;
}
return newState;
2021-04-22 22:05:29 -07:00
default:
return newState;
}
2021-04-22 12:16:15 -07:00
}
export type State = {
common: CommonState;
};
export type CommonState = {
walletProvider?: string;
isWalletConnected: boolean;
2021-04-22 22:05:29 -07:00
network: Network;
2021-04-22 12:16:15 -07:00
};
export const networks: Networks = {
mainnet: {
// Cluster.
2021-04-22 22:05:29 -07:00
label: "Mainnet Beta",
url: "https://solana-api.projectserum.com",
explorerClusterSuffix: "",
2021-04-22 12:16:15 -07:00
multisigProgramId: new PublicKey(
"msigmtwzgXJHj2ext4XJjCDmpbcMuufFb5cHuwg6Xdt"
2021-04-22 22:05:29 -07:00
),
multisigUpgradeAuthority: new PublicKey(
"3uztpEgUmvirDBYRXgDamUDZiU5EcgTwArQ2pULtHJPC"
2021-04-22 12:16:15 -07:00
),
},
devnet: {
// Cluster.
2021-04-22 22:05:29 -07:00
label: "Devnet",
url: "https://devnet.solana.com",
explorerClusterSuffix: "devnet",
2021-04-22 12:16:15 -07:00
multisigProgramId: new PublicKey(
2021-04-22 22:05:29 -07:00
"F3Uf5F61dmht1xuNNNkk3jnzj82TY56vVjVEhZALRkN"
2021-04-22 12:16:15 -07:00
),
},
// Fill in with your local cluster addresses.
localhost: {
// Cluster.
2021-04-22 22:05:29 -07:00
label: "Localhost",
url: "http://localhost:8899",
explorerClusterSuffix: "localhost",
2021-04-22 12:16:15 -07:00
multisigProgramId: new PublicKey(
2021-04-22 22:05:29 -07:00
"9z7Pq56To96qbVLzuBcf47Lc7u8uUWZh6k5rhcaTsDjz"
2021-04-22 12:16:15 -07:00
),
},
};
export const initialState: State = {
common: {
isWalletConnected: false,
2021-04-22 22:05:29 -07:00
walletProvider: "https://www.sollet.io",
network: networks.mainnet,
2021-04-22 12:16:15 -07:00
},
};
type Networks = { [label: string]: Network };
export type Network = {
// Cluster.
label: string;
url: string;
explorerClusterSuffix: string;
multisigProgramId: PublicKey;
2021-04-22 22:05:29 -07:00
multisigUpgradeAuthority?: PublicKey;
2021-04-22 12:16:15 -07:00
};