hyuskui

Crypto Elements

Wallet, token and DeFi patterns, built from hyuskui components. Each is a GPUI view you copy into your project.

Wallet connection, addresses, token amounts, swaps, transaction status, signing requests and DeFi positions: the pieces an onchain app's interface is made of. There is no hyuskui crate to depend on. A pattern is a single Rust file that composes components such as Dialog, Form and Data Table, so you own every line.

UI only

These are presentational, controlled views. They never hold a key, sign, or call an RPC node. The host app connects the wallet, reads balances and quotes, and sends transactions; the pattern shows what it is given and calls your handlers when the user clicks Connect, Approve, Swap or Sign. Every demo runs on sample data with obviously fake addresses such as 0x0000…11cE. Tokens use generic symbols such as ETH and USDC with their real decimals; there are no real addresses, chains or protocols.

Amounts and addresses

Mistakes here cost money, so the patterns share one small module, Onchain, with no floating point in it:

  • Amounts are u128 counts of base units. parse_units rejects more decimals than the token has instead of rounding, and display formatting rounds down so a balance never looks larger than it is. Max fills the exact balance. u128 is smaller than Solidity's uint256; values that don't fit are errors, never wrapped.
  • Addresses are EIP-55 checksummed. A mixed-case address with a wrong checksum is rejected as a likely typo. 0x1234…abcd is for display only: copy, compare and send the full address.
  • Rates, slippage, price impact, vault shares and health factors are integer math in basis points.

Patterns

Wallet ConnectA connect button that opens a wallet-choice dialog, waits while the wallet asks the user to approve, and then becomes an account menu with the truncated address and balance.AddressAn account shown as its name when it has one, the address truncated to 0x1234…abcd, and an identicon drawn from the address hash. Copy puts the full checksummed address on the clipboard.Token Amount InputAn amount field that knows its token's decimals: it rejects more fraction digits than the token has instead of rounding, Max fills the exact balance, and the hint shows the balance and the amount's value. Validation runs through Form.Token PickerA token button that opens a searchable dialog: common tokens as chips, then every token with its balance. Search matches symbol and name; a pasted address is checked against its EIP-55 checksum before it is offered as an unlisted token.Swap CardTwo token amounts with a flip button between them, the quote's rate, price impact and minimum received, and slippage settings in a popover. The amount is validated with Form against the token's decimals and balance; the button says what is wrong until it can swap.Network SwitcherA menu of networks with the current one checked. Picking another asks the wallet to switch and shows a spinner until it answers; a network the app doesn't support yet is disabled.Balance ListToken balances with their USD value and 24h change, largest first, under the account's total. Values are integer cents computed from base units and prices; small balances can be hidden.Gas EstimateThe network fee for a transaction at three speeds: fee per gas in gwei, the total in ETH and USD, and the expected wait. Fees are gas units times wei per gas, all integers.Transaction StatusA submitted transaction as pending, confirmed or failed, with its hash, confirmations and a block-explorer link, mirrored by a toast that turns from loading into success or error.Transaction HistoryAn account's recent transactions grouped by day: what each did in plain words, when, and whether it is pending or failed, with a link to the block explorer. Tabs filter by kind.Approve Then SwapThe two transactions a token swap can need, as numbered steps: approve the router to spend exactly the amount (or, by choice, an unlimited allowance), then swap. A step waits on the wallet, then on the network, before the next one unlocks. Enough allowance skips step one.Signing RequestA dialog that previews an EIP-712 typed-data signature before the wallet asks for it: who is asking, on which chain and contract, and every field of the message with amounts shown in their token's units and full addresses. Reject and Sign are the host's handlers.Vault DepositA staking or vault card: APY, deposit and withdraw tabs, an amount checked against the wallet or the position, and a preview of the shares minted or assets returned, rounded down the way ERC-4626 vaults round.LP Position RangeA concentrated-liquidity range: min and max price over a histogram of the pool's liquidity, with the current price marked. The position earns fees only while the price is inside its range, so the card says when it is in range and when it isn't.Lending Health FactorA lending position's health factor on a meter marked at the liquidation line, over a summary of what is supplied and borrowed. Drag the slider to borrow more and watch the factor fall. All values are integer cents and basis points.Bridge CardMoves a token between networks: from and to chains with a swap button, an amount validated with Form, and the route's estimated time, fee and the amount that arrives, all in integer base units.Portfolio TableHoldings in a Data Table: asset, price, balance, value, 24h change and share of the portfolio, sortable and filterable. Values sort as integer cents, never as display strings.

Full pages built from these patterns, a swap page, a portfolio dashboard and a staking page, are on the Crypto blocks tab.

Installation

  1. Add the components

    Each pattern lists the components it uses. Most build on Onchain, Button and Card:

    $ cargo hyuskui add onchain button card
  2. Add the crates

    Onchain hashes addresses with Keccak-256. The CLI copies files only, so add the crate yourself:

    $ cargo add sha3@0.10
  3. Copy a pattern

    Open a pattern, copy its code into your project, for example src/crypto/swap_card.rs, and render the view like any other. Replace the sample data with what your wallet and RPC layer report, and call cx.notify() when it changes.

    // src/main.rs
    mod crypto {
        pub mod swap_card;
    }