evm: generate wallet seed, fix token send value.split error
This commit is contained in:
@@ -10,7 +10,13 @@ import { syncTransactionHistory } from '../../lib/sync'
|
|||||||
import { eq, and } from 'drizzle-orm'
|
import { eq, and } from 'drizzle-orm'
|
||||||
import { db } from '../../lib/db'
|
import { db } from '../../lib/db'
|
||||||
import { getClient } from '../../lib/viem'
|
import { getClient } from '../../lib/viem'
|
||||||
import { formatGwei, parseEther, parseUnits, encodeFunctionData, createWalletClient } from 'viem'
|
import {
|
||||||
|
formatGwei,
|
||||||
|
parseEther,
|
||||||
|
parseUnits,
|
||||||
|
encodeFunctionData,
|
||||||
|
createWalletClient,
|
||||||
|
} from 'viem'
|
||||||
import { mnemonicToAccount } from 'viem/accounts'
|
import { mnemonicToAccount } from 'viem/accounts'
|
||||||
import { getChain } from '../../lib/viem/getChain'
|
import { getChain } from '../../lib/viem/getChain'
|
||||||
import { getChainID } from '../../lib/alchemy/network'
|
import { getChainID } from '../../lib/alchemy/network'
|
||||||
@@ -517,9 +523,7 @@ export function createEvmHandlers(
|
|||||||
name: vaultKey,
|
name: vaultKey,
|
||||||
value: phrase,
|
value: phrase,
|
||||||
})
|
})
|
||||||
await db
|
await db.insert(evmWallets).values({
|
||||||
.insert(evmWallets)
|
|
||||||
.values({
|
|
||||||
id,
|
id,
|
||||||
name,
|
name,
|
||||||
passwordHash: passwordHash ?? null,
|
passwordHash: passwordHash ?? null,
|
||||||
@@ -590,6 +594,7 @@ export function createEvmHandlers(
|
|||||||
name: 'alchemy_key',
|
name: 'alchemy_key',
|
||||||
})
|
})
|
||||||
if (!key) throw new Error('API key not set')
|
if (!key) throw new Error('API key not set')
|
||||||
|
const _amount = String(amount)
|
||||||
const account = mnemonicToAccount(seed)
|
const account = mnemonicToAccount(seed)
|
||||||
const id = getChainID(chainid)
|
const id = getChainID(chainid)
|
||||||
if (!id) throw new Error('Unsupported chain')
|
if (!id) throw new Error('Unsupported chain')
|
||||||
@@ -614,7 +619,10 @@ export function createEvmHandlers(
|
|||||||
const data = encodeFunctionData({
|
const data = encodeFunctionData({
|
||||||
abi: erc20Abi,
|
abi: erc20Abi,
|
||||||
functionName: 'transfer',
|
functionName: 'transfer',
|
||||||
args: [to as `0x${string}`, parseUnits(amount, tokenDecimals)],
|
args: [
|
||||||
|
to as `0x${string}`,
|
||||||
|
parseUnits(_amount, tokenDecimals),
|
||||||
|
],
|
||||||
})
|
})
|
||||||
const hash = await walletClient.sendTransaction({
|
const hash = await walletClient.sendTransaction({
|
||||||
to: contractAddress as `0x${string}`,
|
to: contractAddress as `0x${string}`,
|
||||||
@@ -625,7 +633,7 @@ export function createEvmHandlers(
|
|||||||
}
|
}
|
||||||
const hash = await walletClient.sendTransaction({
|
const hash = await walletClient.sendTransaction({
|
||||||
to: to as `0x${string}`,
|
to: to as `0x${string}`,
|
||||||
value: parseEther(amount),
|
value: parseEther(_amount),
|
||||||
})
|
})
|
||||||
return hash
|
return hash
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -6,7 +6,9 @@
|
|||||||
} from '$lib/states/evm-wallet.svelte.js'
|
} from '$lib/states/evm-wallet.svelte.js'
|
||||||
import { Button } from '$lib/components/ui/button/index.js'
|
import { Button } from '$lib/components/ui/button/index.js'
|
||||||
import { Textarea } from '$lib/components/ui/textarea/index.js'
|
import { Textarea } from '$lib/components/ui/textarea/index.js'
|
||||||
import { navigate } from 'sv-router/generated'
|
import { generateMnemonic } from 'viem/accounts'
|
||||||
|
import { english } from 'viem/accounts'
|
||||||
|
import { navigate } from 'sv-router/generated'
|
||||||
import {
|
import {
|
||||||
Card,
|
Card,
|
||||||
CardContent,
|
CardContent,
|
||||||
@@ -172,14 +174,14 @@
|
|||||||
<CardTitle>
|
<CardTitle>
|
||||||
{#if showCreateForm}
|
{#if showCreateForm}
|
||||||
{@const cur = w.currentWallet}
|
{@const cur = w.currentWallet}
|
||||||
{cur ? `Add Another Wallet` : `Import Wallet`}
|
{cur ? `Add Another Wallet` : `Import / Create Wallet`}
|
||||||
{:else}
|
{:else}
|
||||||
Import Wallet
|
Import / Create Wallet
|
||||||
{/if}
|
{/if}
|
||||||
</CardTitle>
|
</CardTitle>
|
||||||
<CardDescription>
|
<CardDescription>
|
||||||
Name your wallet and enter your seed phrase to save it
|
Name your wallet and enter your seed phrase to save it
|
||||||
securely
|
securely, or generate a new wallet
|
||||||
</CardDescription>
|
</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
@@ -192,6 +194,14 @@
|
|||||||
<Textarea
|
<Textarea
|
||||||
placeholder="Enter your 12 or 24 word seed phrase"
|
placeholder="Enter your 12 or 24 word seed phrase"
|
||||||
bind:value={inputSeed} />
|
bind:value={inputSeed} />
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
onclick={() => {
|
||||||
|
inputSeed = generateMnemonic(english)
|
||||||
|
}}
|
||||||
|
class="w-full mt-1">
|
||||||
|
Generate Random Seed
|
||||||
|
</Button>
|
||||||
<input
|
<input
|
||||||
type="password"
|
type="password"
|
||||||
placeholder="Set a password (optional)"
|
placeholder="Set a password (optional)"
|
||||||
|
|||||||
@@ -76,7 +76,7 @@
|
|||||||
try {
|
try {
|
||||||
const txHash = await w.send(
|
const txHash = await w.send(
|
||||||
recipient,
|
recipient,
|
||||||
amount,
|
String(amount),
|
||||||
selectedToken.contractAddress || undefined,
|
selectedToken.contractAddress || undefined,
|
||||||
selectedToken.decimals,
|
selectedToken.decimals,
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user