Skip to content

Commit

Permalink
fix salt
Browse files Browse the repository at this point in the history
  • Loading branch information
Aniket-Engg committed Sep 24, 2024
1 parent 77dd815 commit 0f266f4
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions libs/remix-ui/run-tab/src/lib/actions/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export const fillAccountsList = async (plugin: RunTab, dispatch: React.Dispatch<
const provider = plugin.blockchain.getProvider()
let accounts = await plugin.blockchain.getAccounts()
if (provider && provider.startsWith('injected') && accounts?.length) {
await loadSmartAccounts(plugin, accounts[0])
if (plugin.REACT_API.smartAccounts.addresses.length) accounts.push(...plugin.REACT_API.smartAccounts.addresses)
// await loadSmartAccounts(plugin, accounts[0])
// if (plugin.REACT_API.smartAccounts.addresses.length) accounts.push(...plugin.REACT_API.smartAccounts.addresses)
}
if (!accounts) accounts = []

Expand Down Expand Up @@ -106,11 +106,12 @@ export const createSmartAccount = async (plugin: RunTab, dispatch: React.Dispatc
transport: http(bundlerEndpoint)
})
const smartAddresses = Object.keys(plugin.REACT_API.smartAccounts)
console.log('smartAddresses--->', smartAddresses)
// @ts-ignore
const accounts = await window.ethereum!.request({ method: 'eth_requestAccounts' })
console.log('accounts---->', accounts) // Non checksummed
const account = plugin.REACT_API.accounts.selectedAccount

console.log('account---account->', account)
const walletClient: any = createWalletClient({
account,
chain: sepolia,
Expand All @@ -122,17 +123,20 @@ export const createSmartAccount = async (plugin: RunTab, dispatch: React.Dispatc
const smartAccount = new V06.Account.Instance({
...V06.Account.Common.SimpleAccount.base(ethClient, walletClient),
})
const lastSalt = plugin.REACT_API.smartAccounts[smartAddresses[smartAddresses.length - 1]].salt
const lastSalt = smartAddresses.length ? plugin.REACT_API.smartAccounts[smartAddresses[smartAddresses.length - 1]].salt : -1
const salt = lastSalt + 1
console.log('salt---->', salt)
await smartAccount.setSalt(BigInt(salt))
const sender = await smartAccount.getSender()
console.log('sender---->', sender)
if (!smartAddresses.includes(sender)) {
const saDetails: SmartAccountDetails = {
address : sender,
salt,
owner: account,
timestamp: Date.now()
}
console.log('saDetails---->', saDetails)
plugin.REACT_API.smartAccounts[sender] = saDetails
// Save smart accounts in local storage
const smartAccountsStr = localStorage.getItem(localStorageKey)
Expand All @@ -141,7 +145,7 @@ export const createSmartAccount = async (plugin: RunTab, dispatch: React.Dispatc
localStorage.setItem(localStorageKey, JSON.stringify(smartAccountsObj))

plugin.call('notification', 'toast', `smart account created with address ${sender}`)
await fillAccountsList(plugin, dispatch)
// await fillAccountsList(plugin, dispatch)
}
}

Expand Down

0 comments on commit 0f266f4

Please sign in to comment.