Spaces:
Running
Running
Download src/bankml/inftModule.tsx from PYTHAI/bankML-UIF: direct link, hf CLI and curl.
- Browser
- Download file 6.01 kB
-
https://huggingface.co/spaces/PYTHAI/bankML-UIF/resolve/main/src/bankml/inftModule.tsx
- Command line
-
hf download hf://spaces/PYTHAI/bankML-UIF/src/bankml/inftModule.tsx
-
curl -L -o inftModule.tsx https://huggingface.co/spaces/PYTHAI/bankML-UIF/resolve/main/src/bankml/inftModule.tsx
6.01 kB
| // SPDX-License-Identifier: MIT | |
| // The iNFT module: prepares an ERC-7857 mintOpenAgent for the bound THOT generation, as bankml's chain.py. It never | |
| // signs and never sends: the owner copies the unsigned transaction (or the `cast send` line) into their own wallet. | |
| import { useEffect, useState } from 'react'; | |
| import type { ModuleWindowProps, UIFModule } from '../core/modules'; | |
| import { planMint, unsignedTx, VALID_DIMENSIONS, type MintPlan } from './inft'; | |
| import { currentManifest } from './thotModule'; | |
| const PREFS = 'bankml-ui:inft'; | |
| interface Prefs { to: string; contract: string; chainId: string; dimensions: number; parallelUnits: number } | |
| const DEFAULTS: Prefs = { to: '', contract: '', chainId: '', dimensions: 768, parallelUnits: 1 }; | |
| const loadPrefs = (): Prefs => { | |
| try { | |
| return { ...DEFAULTS, ...JSON.parse(localStorage.getItem(PREFS) || '{}') }; | |
| } catch { | |
| return DEFAULTS; | |
| } | |
| }; | |
| const ADDRESS = /^0x[0-9a-fA-F]{40}$/; | |
| function Copy({ text, label }: { text: string; label: string }) { | |
| const [done, setDone] = useState(false); | |
| return ( | |
| <button type="button" className="uif-link" onClick={() => navigator.clipboard?.writeText(text).then(() => { setDone(true); setTimeout(() => setDone(false), 1500); })}> | |
| {done ? 'copied' : label} | |
| </button> | |
| ); | |
| } | |
| function InftBody({ uif }: ModuleWindowProps) { | |
| const [p, setP] = useState<Prefs>(loadPrefs); | |
| const [plan, setPlan] = useState<MintPlan | null>(null); | |
| const [error, setError] = useState<string | null>(null); | |
| const manifest = currentManifest(); | |
| const set = (patch: Partial<Prefs>) => | |
| setP(prev => { | |
| const next = { ...prev, ...patch }; | |
| try { localStorage.setItem(PREFS, JSON.stringify(next)); } catch { /* storage off */ } | |
| return next; | |
| }); | |
| useEffect(() => { | |
| setError(null); | |
| setPlan(null); | |
| if (!manifest || !ADDRESS.test(p.to)) return; | |
| planMint(manifest, uif.context.persona ?? {}, p.to, { dimensions: p.dimensions, parallelUnits: p.parallelUnits }) | |
| .then(setPlan) | |
| .catch(e => setError((e as Error).message)); | |
| // the bound generation and the inputs decide the plan | |
| // eslint-disable-next-line react-hooks/exhaustive-deps | |
| }, [manifest?.identity?.cid, p.to, p.dimensions, p.parallelUnits, uif.context.personaText]); | |
| const tx = plan && ADDRESS.test(p.contract) ? unsignedTx(plan, p.contract, p.to, p.chainId ? Number(p.chainId) : undefined) : null; | |
| return ( | |
| <div className="uif-window-stack"> | |
| <p className="uif-window-hint bk-inft-warn"> | |
| Prepares only: this page never signs and never sends. You sign in your own wallet. The house contract (iNFT_7857, ERC-7857) is | |
| not deployed on a public chain today, its audit is not cleared, and minting needs MINTER_ROLE. | |
| </p> | |
| {!manifest ? ( | |
| <p className="uif-window-empty">Bind a THOT generation first (▤ → THOT → Bind): the mint commits to one generation forever.</p> | |
| ) : ( | |
| <p className="uif-window-hint"> | |
| Generation {manifest.bundle.generation} · <code title={manifest.identity.cid}>{manifest.identity.name.slice(0, 28)}…</code> | |
| </p> | |
| )} | |
| <div className="bk-inft-grid"> | |
| <label>owner (to)<input className="uif-input" value={p.to} onChange={e => set({ to: e.target.value.trim() })} placeholder="0x… (20 bytes)" aria-invalid={!!p.to && !ADDRESS.test(p.to)} /></label> | |
| <label>contract<input className="uif-input" value={p.contract} onChange={e => set({ contract: e.target.value.trim() })} placeholder="0x… iNFT_7857" aria-invalid={!!p.contract && !ADDRESS.test(p.contract)} /></label> | |
| <label>chain id<input className="uif-input" value={p.chainId} onChange={e => set({ chainId: e.target.value.replace(/\D/g, '') })} placeholder="optional" /></label> | |
| <label>dimensions<select className="uif-input" value={p.dimensions} onChange={e => set({ dimensions: Number(e.target.value) })}>{VALID_DIMENSIONS.map(d => <option key={d} value={d}>{d}</option>)}</select></label> | |
| <label>parallel units<input className="uif-input" type="number" min={0} max={255} value={p.parallelUnits} onChange={e => set({ parallelUnits: Math.max(0, Math.min(255, Number(e.target.value) || 0)) })} /></label> | |
| </div> | |
| {error && <p className="uif-window-note is-error">{error}</p>} | |
| {plan && ( | |
| <div className="bk-inft-plan"> | |
| <table className="bk-thot-facets"> | |
| <tbody> | |
| {Object.entries(plan.args).map(([k, v]) => ( | |
| <tr key={k}><td>{k}</td><td><code title={String(v)}>{String(v).length > 34 ? String(v).slice(0, 34) + '…' : String(v)}</code></td></tr> | |
| ))} | |
| </tbody> | |
| </table> | |
| <div className="uif-window-row"><b>calldata</b> <span className="uif-window-hint">{(plan.calldata.length - 2) / 2} bytes</span> <Copy text={plan.calldata} label="copy" /></div> | |
| {tx ? ( | |
| <> | |
| <div className="uif-window-row"><b>unsigned transaction</b> <Copy text={JSON.stringify(tx.tx, null, 2)} label="copy JSON" /></div> | |
| <div className="uif-window-row"><b>cast send</b> <Copy text={tx.cast} label="copy command" /></div> | |
| <pre className="uif-window-preview bk-inft-cast">{tx.cast}</pre> | |
| </> | |
| ) : ( | |
| <p className="uif-window-hint">Give the contract address for the unsigned transaction and the cast line.</p> | |
| )} | |
| <p className="uif-window-hint">{plan.note}</p> | |
| </div> | |
| )} | |
| {!plan && manifest && !ADDRESS.test(p.to) && <p className="uif-window-hint">Give the owner's address (the token is minted to it).</p>} | |
| </div> | |
| ); | |
| } | |
| export const inftModule: UIFModule = { | |
| id: 'inft', | |
| label: 'iNFT', | |
| windows: [ | |
| { | |
| id: 'inft', | |
| file: 'iNFT', | |
| icon: '⬡', | |
| summary: 'Prepare an iNFT mint of the bound THOT generation (you sign)', | |
| Body: InftBody, | |
| detail: () => (currentManifest() ? 'ready to prepare' : 'bind THOT first'), | |
| }, | |
| ], | |
| }; | |