separate Multi Coins and Monero into distinct account types with startup login choice

- Removed monero from shared networks array; monero is now its own separate account type
- Added accountType state (null/'multi'/'monero') to wallet, stored in memory only
- Added login(type) method: chooses between EVM vault flow and Monero RPC flow
- Added logout() method that resets all per-account state
- On app startup, user picks Multi Coins (ETH/BSC/Polygon) or Monero
- isLocked getter now checks accountType === 'multi' instead of excluding monero by network id
- Moved ETH/BSC/Polygon routes under /multicoin/ base path
- /multicoin, /multicoin/bsc, /multicoin/polygon with updated navTarget routing
- Root / shows welcome/login choice, redirects if already logged in
- Fixed moneroListWallets timing: runs inside login('monero') after RPC manager exists
- Removed cross-tab links between monero and multicoin, only logout remains
This commit is contained in:
2026-05-18 05:13:50 +08:00
parent 9c856129d8
commit 6142b27c49
9 changed files with 468 additions and 333 deletions
@@ -65,21 +65,51 @@
}) })
function navTarget(id: NetworkId): string { function navTarget(id: NetworkId): string {
if (id === 'eth') return '/' if (id === 'eth') return '/multicoin'
return `/${id}` return `/multicoin/${id}`
} }
let initStarted = false let initStarted = false
$effect(() => { $effect(() => {
if (!initStarted) { if (!initStarted) {
initStarted = true initStarted = true
w.init().then(() => w.switchNetwork(networkId)) w.init().then(async () => {
if (w.accountType === 'multi') {
await w.switchNetwork(networkId)
}
})
} }
}) })
</script> </script>
{#if !w.ready} {#if !w.ready}
{:else if !w.vaultExists} <div class="mx-auto mt-16 max-w-md text-center text-muted-foreground text-sm">Loading...</div>
{:else if !w.accountType}
<div class="mx-auto mt-24 max-w-sm">
<Card>
<CardHeader class="text-center">
<CardTitle>Welcome</CardTitle>
<CardDescription>Choose an account type to get started</CardDescription>
</CardHeader>
<CardContent>
<div class="flex flex-col gap-3">
<Button
onclick={() => w.login('multi')}
class="w-full">
Multi Coins (ETH / BSC / Polygon)
</Button>
<Button
onclick={() => navigate('/monero')}
variant="outline"
class="w-full">
Monero
</Button>
</div>
</CardContent>
</Card>
</div>
{:else if w.accountType === 'multi'}
{#if !w.vaultExists}
<Card> <Card>
<CardHeader> <CardHeader>
<CardTitle>Import Wallet</CardTitle> <CardTitle>Import Wallet</CardTitle>
@@ -152,7 +182,7 @@
{:else} {:else}
<div class="flex flex-col gap-4"> <div class="flex flex-col gap-4">
<div class="flex gap-1 justify-center" role="group"> <div class="flex gap-1 justify-center" role="group">
{#each w.networks as net} {#each w.evmNetworks as net}
<button <button
class="cursor-pointer rounded-md px-2.5 py-1 text-xs font-medium transition-colors {w.network === class="cursor-pointer rounded-md px-2.5 py-1 text-xs font-medium transition-colors {w.network ===
net.id net.id
@@ -162,6 +192,11 @@
{net.name} {net.name}
</button> </button>
{/each} {/each}
<button
class="cursor-pointer rounded-md px-2.5 py-1 text-xs font-medium transition-colors bg-muted text-muted-foreground hover:bg-muted/80"
onclick={() => w.logout()}>
Logout
</button>
</div> </div>
<Card> <Card>
@@ -382,3 +417,4 @@
</Card> </Card>
</div> </div>
{/if} {/if}
{/if}
+44 -12
View File
@@ -27,15 +27,16 @@ export const networks = [
chainid: '1', chainid: '1',
explorerUrl: 'https://etherscan.io/tx/', explorerUrl: 'https://etherscan.io/tx/',
}, },
{ ] as const
const moneroNetwork = {
id: 'monero', id: 'monero',
name: 'Monero', name: 'Monero',
rpc: '', rpc: '',
symbol: 'XMR', symbol: 'XMR',
chainid: '', chainid: '',
explorerUrl: 'https://moneroblocks.info/tx/', explorerUrl: 'https://moneroblocks.info/tx/',
}, } as const
] as const
export type NetworkId = (typeof networks)[number]['id'] export type NetworkId = (typeof networks)[number]['id']
@@ -53,7 +54,10 @@ export const atomicToXmr = (atomic: string): string => {
return frac ? `${whole}.${frac}` : `${whole}` return frac ? `${whole}.${frac}` : `${whole}`
} }
export type AccountType = 'multi' | 'monero'
export const Wallet = () => { export const Wallet = () => {
let accountType = $state<AccountType | null>(null)
let seed = $state('') let seed = $state('')
let address = $state('') let address = $state('')
let balance = $state('0') let balance = $state('0')
@@ -94,8 +98,6 @@ export const Wallet = () => {
return { salt: s, hash } return { salt: s, hash }
} }
const isMonero = () => network === 'monero'
const init = async () => { const init = async () => {
if (!electrobun.rpc) return if (!electrobun.rpc) return
const [raw, rawError] = await tryCatch( const [raw, rawError] = await tryCatch(
@@ -122,20 +124,46 @@ export const Wallet = () => {
) )
if (ph) passwordHash = ph if (ph) passwordHash = ph
await checkMoneroStatus()
await checkBiometric() await checkBiometric()
ready = true ready = true
} }
const switchNetwork = async (id: NetworkId) => { const login = async (type: AccountType) => {
network = id accountType = type
if (id === 'monero') { if (type === 'multi') {
await checkMoneroStatus() if (!seed && vaultExists) {
await loadSeed()
}
if (seed) await switchNetwork(network)
} else if (type === 'monero') {
if (moneroInstalled && !moneroRunning) { if (moneroInstalled && !moneroRunning) {
await moneroStart() await moneroStart()
await checkMoneroStatus() await checkMoneroStatus()
} }
await moneroListWallets() await moneroListWallets()
} else if (seed) { }
}
const logout = () => {
accountType = null
seed = ''
address = ''
balance = '0'
tokenBalances = []
transactions = []
moneroWalletOpen = false
moneroBalAtomic = '0'
moneroUnlockedAtomic = '0'
moneroAddress = ''
moneroTxs = []
moneroWalletName = ''
moneroAccounts = []
}
const switchNetwork = async (id: NetworkId) => {
network = id
if (seed) {
await refresh() await refresh()
} }
} }
@@ -448,8 +476,9 @@ export const Wallet = () => {
return { return {
get isLocked() { get isLocked() {
return vaultExists && !seed && network !== 'monero' return accountType === 'multi' && vaultExists && !seed
}, },
get accountType() { return accountType },
get seed() { return seed }, get seed() { return seed },
get address() { return address }, get address() { return address },
get balance() { return balance }, get balance() { return balance },
@@ -464,9 +493,10 @@ export const Wallet = () => {
get vaultExists() { return vaultExists }, get vaultExists() { return vaultExists },
get ready() { return ready }, get ready() { return ready },
get networks() { return networks }, get networks() { return networks },
get moneroNetwork() { return moneroNetwork },
get evmNetworks() { return networks },
get apiKey() { return apiKey }, get apiKey() { return apiKey },
get transactions() { return transactions }, get transactions() { return transactions },
isMonero,
get moneroRunning() { return moneroRunning }, get moneroRunning() { return moneroRunning },
get moneroWalletOpen() { return moneroWalletOpen }, get moneroWalletOpen() { return moneroWalletOpen },
get moneroConnected() { return moneroConnected }, get moneroConnected() { return moneroConnected },
@@ -487,6 +517,8 @@ export const Wallet = () => {
get passwordSet() { return !!passwordHash }, get passwordSet() { return !!passwordHash },
refresh, refresh,
init, init,
login,
logout,
lock, lock,
unlockWithBiometrics, unlockWithBiometrics,
unlockWithPassword, unlockWithPassword,
-5
View File
@@ -1,5 +0,0 @@
<script lang="ts"></script>
<h1>About</h1>
<p>This is another page</p>
+46 -3
View File
@@ -1,7 +1,50 @@
<script lang="ts"> <script lang="ts">
import EvmDashboard from '$lib/components/EvmDashboard.svelte' import { wallet } from '$lib/states/wallet.svelte.js'
import { Button } from '$lib/components/ui/button/index.js'
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '$lib/components/ui/card/index.js'
import { navigate } from 'sv-router/generated'
const w = wallet
let initStarted = false
$effect(() => {
if (!initStarted) {
initStarted = true
w.init()
}
})
</script> </script>
<div class="mx-auto mt-16 max-w-md"> <div class="mx-auto mt-24 max-w-sm">
<EvmDashboard networkId="eth" /> {#if !w.ready}
<p class="text-center text-muted-foreground text-sm">Loading...</p>
{:else if w.accountType}
{#if w.accountType === 'multi'}
{navigate('/multicoin')}
{:else}
{navigate('/monero')}
{/if}
{:else}
<Card>
<CardHeader class="text-center">
<CardTitle>Welcome</CardTitle>
<CardDescription>Choose an account type to get started</CardDescription>
</CardHeader>
<CardContent>
<div class="flex flex-col gap-3">
<Button
onclick={() => navigate('/multicoin')}
class="w-full">
Multi Coins (ETH / BSC / Polygon)
</Button>
<Button
onclick={() => navigate('/monero')}
variant="outline"
class="w-full">
Monero
</Button>
</div>
</CardContent>
</Card>
{/if}
</div> </div>
+39 -17
View File
@@ -1,5 +1,5 @@
<script lang="ts"> <script lang="ts">
import { wallet, atomicToXmr, type NetworkId } from '$lib/states/wallet.svelte.js' import { wallet, atomicToXmr } from '$lib/states/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 { Input } from '$lib/components/ui/input/index.js' import { Input } from '$lib/components/ui/input/index.js'
@@ -16,11 +16,6 @@
const w = wallet const w = wallet
function navTarget(id: NetworkId): string {
if (id === 'eth') return '/'
return `/${id}`
}
let moneroWalletName = $state('') let moneroWalletName = $state('')
let moneroWalletPass = $state('') let moneroWalletPass = $state('')
let moneroMnemonic = $state('') let moneroMnemonic = $state('')
@@ -32,27 +27,53 @@
$effect(() => { $effect(() => {
if (!initStarted) { if (!initStarted) {
initStarted = true initStarted = true
w.init().then(() => w.switchNetwork('monero')) w.init().then(async () => {
if (w.accountType === 'monero') return
await w.login('monero')
})
} }
}) })
</script> </script>
<div class="mx-auto mt-16 max-w-md"> <div class="mx-auto mt-16 max-w-md">
<div class="flex flex-col gap-4"> <div class="flex flex-col gap-4">
<div class="flex gap-1 justify-center" role="group"> {#if !w.ready}
{#each w.networks as net} <p class="text-center text-muted-foreground text-sm mt-8">Loading...</p>
{:else if !w.accountType}
<Card>
<CardHeader class="text-center">
<CardTitle>Welcome</CardTitle>
<CardDescription>Choose an account type to get started</CardDescription>
</CardHeader>
<CardContent>
<div class="flex flex-col gap-3">
<Button
onclick={() => navigate('/multicoin')}
variant="outline"
class="w-full">
Multi Coins (ETH / BSC / Polygon)
</Button>
<Button
onclick={() => w.login('monero')}
class="w-full">
Monero
</Button>
</div>
</CardContent>
</Card>
{:else if w.accountType === 'monero'}
<div class="flex items-center justify-center gap-1 flex-wrap" role="group">
<button <button
class="cursor-pointer rounded-md px-2.5 py-1 text-xs font-medium transition-colors {w.network === class="cursor-pointer rounded-md px-2.5 py-1 text-xs font-medium transition-colors bg-primary text-primary-foreground">
net.id Monero
? 'bg-primary text-primary-foreground' </button>
: 'bg-muted text-muted-foreground hover:bg-muted/80'}" <button
onclick={() => navigate(navTarget(net.id))}> class="cursor-pointer rounded-md px-2.5 py-1 text-xs font-medium transition-colors bg-muted text-muted-foreground hover:bg-muted/80"
{net.name} onclick={() => w.logout()}>
Logout
</button> </button>
{/each}
</div> </div>
<!-- MONERO DASHBOARD -->
{#if w.moneroDownloading} {#if w.moneroDownloading}
<Card> <Card>
<CardContent> <CardContent>
@@ -276,5 +297,6 @@
</CardContent> </CardContent>
</Card> </Card>
{/if} {/if}
{/if}
</div> </div>
</div> </div>
@@ -0,0 +1,7 @@
<script lang="ts">
import EvmDashboard from '$lib/components/EvmDashboard.svelte'
</script>
<div class="mx-auto mt-16 max-w-md">
<EvmDashboard networkId="eth" />
</div>
@@ -51,7 +51,7 @@
<Button <Button
variant="outline" variant="outline"
size="sm" size="sm"
onclick={() => navigate('/')} onclick={() => navigate('/multicoin')}
class="mb-4"> class="mb-4">
&larr; Back &larr; Back
</Button> </Button>