Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@tanstack/react-query": "^5.90.10",
"@tanstack/react-table": "^8.21.3",
"@types/katex": "^0.16.7",
"@unicitylabs/sphere-sdk": "0.10.2",
"@unicitylabs/sphere-sdk": "0.10.3",
"@unicitylabs/sphere-ui": "^0.1.23",
"crypto-js": "^4.2.0",
"elliptic": "^6.6.1",
Expand Down
7 changes: 5 additions & 2 deletions src/components/wallet/L3/modals/PaymentRequestModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { type IncomingPaymentRequest, PaymentRequestStatus } from '../hooks/useI
import { getErrorMessage } from '../../../../sdk/errors';
import { AnimatePresence, motion } from 'framer-motion';
import { useState } from 'react';
import { AmountFormatUtils } from '../utils/currency';
import { TokenRegistry, formatAmount } from '@unicitylabs/sphere-sdk';
import { WalletScreen } from '../../ui/WalletScreen';
import { ModalHeader, EmptyState } from '../../ui';

Expand Down Expand Up @@ -126,7 +126,10 @@ interface RequestCardProps {

function RequestCard({ req, error, onPay, onReject, isProcessing, isGlobalDisabled }: RequestCardProps) {
const isPending = req.status === PaymentRequestStatus.PENDING;
const amountDisplay = AmountFormatUtils.formatDisplayAmount(req.amount.toString(), req.coinId);
const amountDisplay = formatAmount(req.amount.toString(), {
decimals: TokenRegistry.getInstance().getDecimals(req.coinId),
maxFractionDigits: 6,
});
const timeAgo = getTimeAgo(req.timestamp);

// Status styling
Expand Down
10 changes: 5 additions & 5 deletions src/components/wallet/L3/modals/SendModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useState, useEffect, useRef, useCallback } from 'react';
import { motion, AnimatePresence } from 'framer-motion';
import { ArrowRight, Loader2, User, CheckCircle, Coins, Hash, Copy, Check } from 'lucide-react';
import type { Asset } from '@unicitylabs/sphere-sdk';
import { toSmallestUnit } from '@unicitylabs/sphere-sdk';
import { parseTokenAmount, safeParseTokenAmount } from '@unicitylabs/sphere-sdk';
import { useAssets, useTransfer, formatAmount } from '../../../../sdk';
import { getErrorMessage } from '../../../../sdk/errors';
import { useSphereContext } from '../../../../sdk/hooks/core/useSphere';
Expand Down Expand Up @@ -131,8 +131,8 @@ export function SendModal({ isOpen, onClose, prefill, asModal }: SendModalProps)
const handleDetailsNext = async () => {
if (!selectedAsset || !recipient.trim() || !amountInput) return;

const targetAmount = toSmallestUnit(amountInput, selectedAsset.decimals);
if (targetAmount <= 0n) return;
const targetAmount = safeParseTokenAmount(amountInput, selectedAsset.decimals);
if (targetAmount === null || targetAmount <= 0n) return;
if (targetAmount > BigInt(selectedAsset.totalAmount)) return;

setIsCheckingRecipient(true);
Expand Down Expand Up @@ -180,7 +180,7 @@ export function SendModal({ isOpen, onClose, prefill, asModal }: SendModalProps)
setRecipientError(null);

try {
const amount = toSmallestUnit(amountInput, selectedAsset.decimals).toString();
const amount = parseTokenAmount(amountInput, selectedAsset.decimals).toString();
await transfer({
coinId: selectedAsset.coinId,
amount,
Expand Down Expand Up @@ -229,7 +229,7 @@ export function SendModal({ isOpen, onClose, prefill, asModal }: SendModalProps)

{/* 2. DETAILS (recipient + amount) */}
{step === 'details' && selectedAsset && (() => {
const insufficientBalance = amountInput !== '' && toSmallestUnit(amountInput, selectedAsset.decimals) > BigInt(selectedAsset.totalAmount);
const insufficientBalance = (safeParseTokenAmount(amountInput, selectedAsset.decimals) ?? 0n) > BigInt(selectedAsset.totalAmount);
const usdValue = selectedAsset.priceUsd != null && amountInput
? (parseFloat(amountInput) * selectedAsset.priceUsd).toFixed(2)
: null;
Expand Down
8 changes: 4 additions & 4 deletions src/components/wallet/L3/modals/SendPaymentRequestModal.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState, useEffect, useRef } from 'react';
import { motion, AnimatePresence } from 'framer-motion';
import { ArrowRight, Loader2, User, CheckCircle, Hash, Receipt } from 'lucide-react';
import { TokenRegistry, toSmallestUnit } from '@unicitylabs/sphere-sdk';
import { TokenRegistry, parseTokenAmount, safeParseTokenAmount } from '@unicitylabs/sphere-sdk';
import { useSphereContext } from '../../../../sdk/hooks/core/useSphere';
import { getErrorMessage } from '../../../../sdk/errors';
import { WalletScreen } from '../../ui/WalletScreen';
Expand Down Expand Up @@ -142,8 +142,8 @@ export function SendPaymentRequestModal({ isOpen, onClose, prefill, asModal }: S
// Validate recipient + amount → go to confirm
const handleDetailsNext = async () => {
if (!selectedCoin || !recipient.trim() || !amountInput) return;
const targetAmount = toSmallestUnit(amountInput, selectedCoin.decimals);
if (targetAmount <= 0n) return;
const targetAmount = safeParseTokenAmount(amountInput, selectedCoin.decimals);
if (targetAmount === null || targetAmount <= 0n) return;

setIsCheckingRecipient(true);
setRecipientError(null);
Expand Down Expand Up @@ -188,7 +188,7 @@ export function SendPaymentRequestModal({ isOpen, onClose, prefill, asModal }: S
setError(null);

try {
const amount = toSmallestUnit(amountInput, selectedCoin.decimals).toString();
const amount = parseTokenAmount(amountInput, selectedCoin.decimals).toString();
const recipientStr = recipientMode === 'nametag' ? `@${recipient}` : recipient;

const result = await sphere!.payments.sendPaymentRequest(recipientStr, {
Expand Down
6 changes: 3 additions & 3 deletions src/components/wallet/L3/modals/SwapModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { motion, AnimatePresence } from 'framer-motion';
import { ArrowDownUp, Loader2, CheckCircle, ChevronDown } from 'lucide-react';
import { useAssets, useTransfer } from '../../../../sdk';
import type { Asset } from '@unicitylabs/sphere-sdk';
import { toSmallestUnit, toHumanReadable } from '@unicitylabs/sphere-sdk';
import { parseTokenAmount, toHumanReadable } from '@unicitylabs/sphere-sdk';
import { TokenRegistry } from '@unicitylabs/sphere-sdk';
import { useSphereContext } from '../../../../sdk/hooks/core/useSphere';
import { SPHERE_KEYS } from '../../../../sdk/queryKeys';
Expand Down Expand Up @@ -128,11 +128,11 @@ export function SwapModal({ isOpen, onClose }: SwapModalProps) {
setStep('processing'); setError(null);
try {
// 1. Send the "from" asset to the swap stub recipient (unchanged).
const fromAmountSmallestUnit = toSmallestUnit(fromAmount, fromAsset.decimals);
const fromAmountSmallestUnit = parseTokenAmount(fromAmount, fromAsset.decimals);
await transfer({ recipient: 'sphere-swap', amount: fromAmountSmallestUnit.toString(), coinId: fromAsset.coinId });

// 2. Self-mint the "to" asset to this wallet (replaces the faucet call).
const toAmountSmallestUnit = toSmallestUnit(exchangeInfo.toAmount.toFixed(toAsset.decimals), toAsset.decimals);
const toAmountSmallestUnit = parseTokenAmount(exchangeInfo.toAmount.toFixed(toAsset.decimals), toAsset.decimals);
const mintResult = await sphere.payments.mintFungibleToken(toAsset.coinId, toAmountSmallestUnit);
if (!mintResult.success) throw new Error(mintResult.error);

Expand Down
49 changes: 0 additions & 49 deletions src/components/wallet/L3/utils/currency.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/sdk/hooks/payments/useTopUp.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { useSphereContext } from '../core/useSphere';
import { SPHERE_KEYS } from '../../queryKeys';
import { TokenRegistry, toSmallestUnit } from '@unicitylabs/sphere-sdk';
import { TokenRegistry, parseTokenAmount } from '@unicitylabs/sphere-sdk';

/** Per-coin result of a top-up mint, for partial-success display. */
export interface TopUpResult {
Expand Down Expand Up @@ -69,7 +69,7 @@ export function useTopUp(): UseTopUpReturn {
return { ...base, success: false, error: 'Not in token registry' };
}
const iconUrl = registry.getIconUrl(def.id) ?? undefined;
const amount = toSmallestUnit(human, def.decimals ?? 0);
const amount = parseTokenAmount(String(human), def.decimals ?? 0);
try {
const res = await sphere.payments.mintFungibleToken(def.id, amount);
return res.success
Expand Down
Loading