Last active
March 20, 2024 03:35
-
-
Save oneleo/bc313b9a23c66643335f04fdcbc146ba to your computer and use it in GitHub Desktop.
Modify this PR for test: https://github.com/pilagod/waallet-extension/pull/62
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
import { type State } from "~background/storage" | |
import { | |
AccountType, | |
getStorage, | |
setStorageTest, | |
type Account | |
} from "./storage" | |
async function main() { | |
const storage = await getStorage() | |
const state = storage.get() | |
await setProvider(state) | |
storage.subscribe(async (state) => { | |
await setProvider(state) | |
}) | |
// For test | |
setStorageTest(storage) | |
} | |
async function setProvider(state: State) { | |
const network = Object.values(state.network).find((n) => n.active) | |
if (!network) { | |
throw new Error("No available network") | |
} | |
const provider = setupWaalletBackgroundProvider({ | |
nodeRpcUrl: network.nodeRpcUrl, | |
bundlerRpcUrl: network.bundlerRpcUrl | |
}) | |
const [account] = Object.values(network.account) | |
if (!account) { | |
throw new Error("No available account") | |
} | |
provider.connect(await initAccount(provider.node, account)) | |
} | |
//... | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
export async function setStorageTest(storage: ObservableStorage<State>) { | |
storage.set( | |
{ | |
network: { | |
[5]: { | |
active: true, | |
chainId: config.chainId, | |
nodeRpcUrl: | |
"https://eth-goerli.g.alchemy.com/v2/<XXX>", | |
bundlerRpcUrl: | |
"https://eth-goerli.g.alchemy.com/v2/<XXX>", | |
account: { | |
...(config.simpleAccountAddress && { | |
[config.simpleAccountAddress]: { | |
type: AccountType.SimpleAccount, | |
address: config.simpleAccountAddress, | |
ownerPrivateKey: config.simpleAccountOwnerPrivateKey | |
} | |
}), | |
...(true && { | |
["0x0a13f225971a93c2bcd7bc24b50bf4d5f58cd6d9"]: { | |
type: AccountType.PasskeyAccount, | |
address: "0x0a13f225971a93c2bcd7bc24b50bf4d5f58cd6d9" | |
} | |
}) | |
}, | |
paymaster: { | |
...(config.verifyingPaymasterAddress && { | |
[config.verifyingPaymasterAddress]: { | |
type: PaymasterType.VerifyingPaymaster, | |
address: config.verifyingPaymasterAddress, | |
ownerPrivateKey: config.verifyingPaymasterOwnerPrivateKey | |
} | |
}) | |
} | |
} | |
} | |
}, | |
{ override: true } | |
) | |
console.log(`setStorageTest`) | |
} | |
// ... | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment