25 lines
699 B
TypeScript
25 lines
699 B
TypeScript
import { networks } from "../constants"
|
|
import * as storage from "./storage"
|
|
|
|
const CHAIN_KEY_PREIFX = "selected_chain_id"
|
|
|
|
export const createChainStorage = () => {
|
|
const getActiveChainId = async (): Promise<String> => {
|
|
let activeChainId = await storage.get(CHAIN_KEY_PREIFX)
|
|
if (!activeChainId) {
|
|
activeChainId = networks.at(0)?.chainId;
|
|
await setActiveChainId(activeChainId)
|
|
}
|
|
return activeChainId
|
|
}
|
|
|
|
const setActiveChainId = async (activeChainId: String | undefined): Promise<void> => {
|
|
await storage.set(CHAIN_KEY_PREIFX, activeChainId)
|
|
}
|
|
|
|
return {
|
|
getActiveChainId,
|
|
setActiveChainId,
|
|
}
|
|
}
|