-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: package versions * fix: remove unnecessary fragmet * fix: move smart account implementations * feat: add abstract smart account lib with safe implementation * feat: add modular smart account implementation
- Loading branch information
1 parent
9942501
commit cdfc562
Showing
21 changed files
with
555 additions
and
682 deletions.
There are no files selected for viewing
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
13 changes: 2 additions & 11 deletions
13
advanced/wallets/react-wallet-v2/src/components/ChainDataMini.tsx
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
27 changes: 10 additions & 17 deletions
27
advanced/wallets/react-wallet-v2/src/components/ChainSmartAddressMini.tsx
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,21 @@ | ||
import ChainAddressMini from './ChainAddressMini' | ||
import { Row, Spinner } from '@nextui-org/react' | ||
import SettingsStore from '@/store/SettingsStore' | ||
import { useSnapshot } from 'valtio' | ||
|
||
interface Props { | ||
chain: | ||
| { | ||
chainId: string | ||
name: string | ||
logo: string | ||
rgb: string | ||
namespace: string | ||
} | ||
| undefined | ||
type SmartAccount = { | ||
address: string | ||
type: string | ||
} | ||
|
||
export default function ChainSmartAddressMini({ chain }: Props) { | ||
const { kernelSmartAccountAddress } = useSnapshot(SettingsStore.state) | ||
interface Props { | ||
account: SmartAccount | ||
} | ||
|
||
if (!kernelSmartAccountAddress) return <Spinner /> | ||
export default function ChainSmartAddressMini({ account }: Props) { | ||
if (!account) return <Spinner /> | ||
return ( | ||
<Row> | ||
<Row>(Kernel)</Row> | ||
<ChainAddressMini address={kernelSmartAccountAddress} /> | ||
<Row>({account.type})</Row> | ||
<ChainAddressMini address={account.address} /> | ||
</Row> | ||
) | ||
} |
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
17 changes: 17 additions & 0 deletions
17
advanced/wallets/react-wallet-v2/src/consts/smartAccounts.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { KernelSmartAccountLib } from '@/lib/smart-accounts/KernelSmartAccountLib' | ||
import { SafeSmartAccountLib } from '@/lib/smart-accounts/SafeSmartAccountLib' | ||
import { goerli, polygonMumbai, sepolia } from 'viem/chains' | ||
|
||
// Types | ||
export const allowedChains = [sepolia, polygonMumbai, goerli] | ||
// build chains so I can access them by id | ||
export const chains = allowedChains.reduce((acc, chain) => { | ||
acc[chain.id] = chain | ||
return acc | ||
}, {} as Record<Chain['id'], Chain>) | ||
export type Chain = typeof allowedChains[number] | ||
|
||
export const availableSmartAccounts = { | ||
safe: SafeSmartAccountLib, | ||
kernel: KernelSmartAccountLib | ||
} |
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
25 changes: 17 additions & 8 deletions
25
advanced/wallets/react-wallet-v2/src/hooks/usePriorityAccounts.ts
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
48 changes: 48 additions & 0 deletions
48
advanced/wallets/react-wallet-v2/src/hooks/useSmartAccounts.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import SettingsStore from '@/store/SettingsStore' | ||
import { | ||
createOrRestoreKernelSmartAccount, | ||
createOrRestoreSafeSmartAccount, | ||
smartAccountWallets | ||
} from '@/utils/SmartAccountUtil' | ||
|
||
import { useSnapshot } from 'valtio' | ||
|
||
export default function useSmartAccounts() { | ||
const { smartAccountEnabled, kernelSmartAccountEnabled, safeSmartAccountEnabled } = useSnapshot( | ||
SettingsStore.state | ||
) | ||
|
||
const initializeSmartAccounts = async (privateKey: string) => { | ||
if (smartAccountEnabled) { | ||
if (kernelSmartAccountEnabled) { | ||
const { kernelSmartAccountAddress } = await createOrRestoreKernelSmartAccount(privateKey) | ||
SettingsStore.setKernelSmartAccountAddress(kernelSmartAccountAddress) | ||
} | ||
if (safeSmartAccountEnabled) { | ||
const { safeSmartAccountAddress } = await createOrRestoreSafeSmartAccount(privateKey) | ||
SettingsStore.setSafeSmartAccountAddress(safeSmartAccountAddress) | ||
} | ||
} | ||
} | ||
|
||
const getAvailableSmartAccounts = () => { | ||
if (!smartAccountEnabled) { | ||
return [] | ||
} | ||
const accounts = [] | ||
for (const [key, lib] of Object.entries(smartAccountWallets)) { | ||
accounts.push({ | ||
address: key.split(':')[1], | ||
type: lib.type, | ||
chain: lib.chain | ||
}) | ||
} | ||
|
||
return accounts | ||
} | ||
|
||
return { | ||
initializeSmartAccounts, | ||
getAvailableSmartAccounts | ||
} | ||
} |
Oops, something went wrong.