Files
wallet/ui/src/components/NearIntentsPanel.tsx
T
grenadeandClaude Opus 5.5 f4cc7a1605
ci / gate (push) Failing after 1m25s
feat(near): the intents account on the Accounts page
Every open wallet with a phrase now shows its NEAR Intents account. Its
NEP-649 key is derived from the seed on each look and dropped; only the
public side leaves Rust. The account's name is a function of that key,
b<base32 of the handle's first 10 bytes>.blackbeard-observer.near, so the
sponsor (#81) creates it there, a restored phrase finds it again with
nothing stored, and the leading b sorts it onto shard 8, which our nodes
serve. The panel says whether the account exists and whether this
wallet's key is on it, and shows its NEAR for gas and every token it
holds inside Intents (one mt_batch_balance_of over the registry's
Intents ids).

The logic is wallet_core::near::account_summary, written against the
NearRpc port and tested with a fake. The command is a shim, and the app
now holds the shard-routed client from #73 and near.toml, which a file
in the data directory can replace.

Corrected on the way: the asset registry said no post-quantum asset is
on Intents. QTC has been, as nep141:qtc.omft.near, since early October.
Quantus's native QTC now maps to it, the token-list fixture gains 1Click's
QTC entry, and the "unmapped asset" tests use Planck's token instead. The
readme no longer says the swap module waits for Quantus's MPC fork.

Verified in a dev run with the dev-phrase fixture: the panel showed
bffbod6n6ey7jdk4j.blackbeard-observer.near as not created yet.

Refs #74

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NUx7SPonBnB3ofU4mH41WT
2026-10-09 13:23:13 +03:00

101 lines
3.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { useQuery } from '@tanstack/react-query'
import { copyText } from '../api/clipboard'
import { nearAccount } from '../api/wallet'
import { formatAmount } from '../lib/format'
/**
* The wallet's NEAR Intents account: the NEAR account its phrase's
* ML-DSA-65 key controls, which the swap routes run through. Named by the
* sponsor from the key, so it is known before it exists; everything here
* is read and decided on the Rust side.
*/
export function NearIntentsPanel({ wallet }: { wallet: string }) {
const account = useQuery({
queryKey: ['near-account', wallet],
queryFn: () => nearAccount(wallet),
staleTime: 30_000,
retry: 1,
})
const a = account.data
return (
<section className="panel">
<div className="panel-head">
<h2 className="panel-title">NEAR Intents account · {wallet}</h2>
{a && (
<span className="muted" style={{ fontSize: 12 }}>
{a.exists ? (a.key_on_account ? 'active' : 'not this wallet’s key') : 'not created yet'}
</span>
)}
</div>
<div className="panel-body">
{account.isPending && <p className="muted">Reading NEAR…</p>}
{account.isError && <p className="error">{account.error.message}</p>}
{a && (
<div data-testid="near-account">
<div className="field">
<label>Account</label>
<div className="mono address">{a.account_id}</div>
<span className="muted" style={{ fontSize: 12 }}>
Controlled only by this wallet’s post-quantum key (ML-DSA-65, derived from its
phrase at {a.derivation_path}). The same phrase finds it again anywhere.
</span>
</div>
{!a.exists && (
<p className="muted">
Swaps run through this account. It is created for you by the wallet’s sponsor,
which is not open yet.
</p>
)}
{a.exists && !a.key_on_account && (
<p className="error">
This account exists but this wallet’s key is not on it, so the wallet cannot use
it.
</p>
)}
{a.exists && (
<table className="table review">
<tbody>
<tr>
<th>Gas</th>
<td className="numeral">
{a.gas ? formatAmount(a.gas) : '—'} NEAR
<span className="muted"> pays this account’s transactions</span>
</td>
</tr>
{a.intents.length === 0 && (
<tr>
<th>Held</th>
<td className="muted">Nothing in NEAR Intents yet.</td>
</tr>
)}
{a.intents.map((b) => (
<tr key={b.token}>
<th>{b.symbol}</th>
<td className="numeral">
{formatAmount(b.amount)} {b.symbol}
</td>
</tr>
))}
</tbody>
</table>
)}
<div className="row">
<button className="button" type="button" onClick={() => copyText(a.account_id)}>
Copy account
</button>
<button
className="button"
type="button"
onClick={() => account.refetch()}
disabled={account.isFetching}
>
{account.isFetching ? 'Reading…' : 'Refresh'}
</button>
</div>
</div>
)}
</div>
</section>
)
}