import { describe, expect, it } from 'vitest'
import {
  formatFundedRowBalanceUsd,
  formatFundedRowUnitPrice,
  sortFundedWalletTokenRows,
  type FundedWalletTokenRow,
} from './walletFundedTokenListing'

describe('walletFundedTokenListing', () => {
  it('sorts native ETH first then by balance USD', () => {
    const rows: FundedWalletTokenRow[] = [
      {
        kind: 'erc20',
        symbol: 'WETH',
        name: 'Wrapped Ether',
        address: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
        decimals: 18,
        logoURI: 'https://example/weth.svg',
        balanceRaw: '1000000000000000000',
        balanceLabel: '1 WETH',
        balanceUsd: 100,
        metaMaskAddable: true,
      },
      {
        kind: 'native',
        symbol: 'ETH',
        name: 'Ether',
        address: null,
        decimals: 18,
        logoURI: 'https://example/eth.svg',
        balanceRaw: '2000000000000000000',
        balanceLabel: '2 ETH',
        balanceUsd: 200,
        metaMaskAddable: false,
      },
    ]

    const sorted = sortFundedWalletTokenRows(rows)
    expect(sorted[0]?.kind).toBe('native')
    expect(sorted[1]?.symbol).toBe('WETH')
  })

  it('formats USD labels', () => {
    expect(formatFundedRowUnitPrice({ priceUsd: 1700.25 })).toContain('$')
    expect(formatFundedRowBalanceUsd({ balanceUsd: 42.5 })).toContain('≈')
    expect(formatFundedRowUnitPrice({ pricingKind: 'lp-share' })).toContain('LP share')
  })
})
