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