Token Approvals

Spending allowances granted to contracts, with revoke. An unlimited approval is stated as "unlimited" rather than rendered as 2²⁵⁶−1, which reads like a display bug — it is a standing permission to move the whole balance, forever.

src/components/ui/token-approvals.tsx

About

From the component's own source, where it was written.

Spending allowances granted to contracts, and a way to revoke them.

An unlimited approval is called out as a risk rather than shown as a number. Wallets grant 2^256-1 by default and it renders as an absurd figure that reads like a display bug; stating "unlimited" is the only honest rendering, because that is exactly what it is — a standing permission to move the entire balance, forever, with no further signature.

Revoking is confirmed inline beside the row. A modal that hides which approval is being revoked is how the wrong one goes.

Install

npx astralyx-ui add token-approvals

Usage

import { TokenApprovals } from '@/components/ui/token-approvals'

<TokenApprovals approvals={approvals} onRevoke={revoke} />

Composer

Change the props and the source below follows.

Approvals32 unlimited
  • USDCUnlimited
    spenderUniswap Routerlast used US$12,480.00 at risk
  • WETH5.00 WETH
    spender1inchlast used
  • DAIUnlimited
    spender0x7a25…488DUS$840.00 at risk
Props
tsx
<TokenApprovals approvals={approvals} onRevoke={revoke} />

Examples

Allowances

API

Generated from the source, so it cannot fall behind the code. One table per exported component, then hooks, functions and types.

TokenApprovals

Extends Omit<ComponentProps<'div'>, 'children'>.

PropTypeDefaultDescription
titlestring'Approvals'—
approvalsApproval[]required{ id, token, spender, spenderName?, allowance?, unlimited?, lastUsed?, atRisk? }.
onRevoke(id: string) => void—Confirmed inline beside the row, since a modal hiding which approval is being revoked is how the wrong one goes.
currencystring'USD'—
localestring'en-GB'—
nowDate——
emptyLabelReactNode'No active approvals'—
unlimitedLabelReactNode'Unlimited'Badge on an unbounded allowance.
revokeLabelReactNode'Revoke'—
spenderLabelReactNode'spender'Precedes the spender address.
lastUsedLabelReactNode'last used'Precedes the last-used time.
confirmNoteReactNode'Revoking costs gas and requires a signature.'—
confirmLabelReactNode'Confirm'—
cancelLabelReactNode'Cancel'—

Types

Approval

Spending allowances granted to contracts, and a way to revoke them.

FieldTypeDescription
idstring—
tokenReactNode—
tokenIcon?ReactNode—
spenderstringThe contract holding the allowance.
spenderName?ReactNode—
allowance?ReactNodeFormatted amount, or omit for unlimited.
unlimited?booleanBadged as a risk rather than shown as a number.
lastUsed?Date—
atRisk?numberFiat value currently exposed under the approval — the figure that makes it concrete.
explorerHref?string—