Skip to content

Commit

Permalink
feat: include persisted address and credentialId in account loading a…
Browse files Browse the repository at this point in the history
…nd creation processes
  • Loading branch information
frankudoags committed Dec 20, 2024
1 parent 4d288fa commit 79ef232
Showing 1 changed file with 33 additions and 12 deletions.
45 changes: 33 additions & 12 deletions src/internal/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,19 @@ export function from<
case 'eth_requestAccounts': {
if (!headless) throw new ox_Provider.UnsupportedMethodError()

const { account } = await AccountDelegation.load(state.client, {
rpId: keystoreHost,
})
const { account, address, credentialId } =
await AccountDelegation.load(state.client, {
rpId: keystoreHost,
address: state.address,
credentialId: state.credentialId,
})

store.setState((x) => ({ ...x, accounts: [account] }))
store.setState((x) => ({
...x,
address,
credentialId,
accounts: [account],
}))

emitter.emit('connect', { chainId: Hex.fromNumber(state.chainId) })
return [account.address] satisfies RpcSchema.ExtractReturnType<
Expand Down Expand Up @@ -163,7 +171,7 @@ export function from<
})
: undefined

const { account } = await (async () => {
const { account, address, credentialId } = await (async () => {
if (createAccount) {
const { label } =
typeof createAccount === 'object' ? createAccount : {}
Expand All @@ -177,12 +185,19 @@ export function from<
return await AccountDelegation.load(state.client, {
authorizeKeys: key ? [key] : undefined,
rpId: keystoreHost,
address: state.address,
credentialId: state.credentialId,
})
})()

const sessions = getActiveSessionKeys(account.keys)

store.setState((x) => ({ ...x, accounts: [account] }))
store.setState((x) => ({
...x,
address,
credentialId,
accounts: [account],
}))

emitter.emit('connect', { chainId: Hex.fromNumber(state.chainId) })

Expand All @@ -208,13 +223,19 @@ export function from<
>) ?? [{}]

// TODO: wait for tx to be included/make counterfactual?
const { account } = await AccountDelegation.create(state.client, {
delegation: state.delegation,
label,
rpId: keystoreHost,
})
const { account, address, credentialId } =
await AccountDelegation.create(state.client, {
delegation: state.delegation,
label,
rpId: keystoreHost,
})

store.setState((x) => ({ ...x, accounts: [account] }))
store.setState((x) => ({
...x,
address,
credentialId,
accounts: [account],
}))

emitter.emit('connect', { chainId: Hex.fromNumber(state.chainId) })
return account.address satisfies RpcSchema.ExtractReturnType<
Expand Down

0 comments on commit 79ef232

Please sign in to comment.