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
Binary file removed .a.swp
Binary file not shown.
Binary file removed .capability.swp
Binary file not shown.
Binary file removed .colored.swp
Binary file not shown.
Binary file removed .for.swp
Binary file not shown.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,6 @@ fix.md
test-results/
# Generated OG images
apps/docs/public/og/
.nitro-static/og/
.nitro-static/og/
# Editor swap files
*.swp
Binary file removed .has.swp
Binary file not shown.
Binary file removed .if.swp
Binary file not shown.
Binary file removed .prompt,.swp
Binary file not shown.
Binary file removed .terminal.swp
Binary file not shown.
Binary file removed .the.swp
Binary file not shown.
Binary file removed .uncomment.swp
Binary file not shown.
2 changes: 1 addition & 1 deletion apps/web/src/features/wallet/components/ConnectButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ function WalletModal({
)
const sep7Uri = useMemo(() => {
const origin =
typeof window === "undefined" ? "https://so4.markets" : window.location.origin
typeof window === "undefined" ? "https://so4.market" : window.location.origin
const callbackUrl = new URL("/", origin).toString()

if (pendingTransactionXdr) {
Expand Down
7 changes: 7 additions & 0 deletions apps/web/src/lib/amount.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@ describe("parseAmount", () => {
const result = parseAmount("1.1234567", { decimals: 6 })
expect(result.value).toBe(1.123456)
})

it("does not lose a unit to floating-point truncation", () => {
// Math.floor(0.57 * 1e7) / 1e7 === 0.5699999
expect(parseAmount("0.57").value).toBe(0.57)
expect(parseAmount("0.57", { decimals: 2 }).value).toBe(0.57)
expect(parseAmount("0.5799999999").value).toBe(0.5799999)
})
})
})

Expand Down
12 changes: 6 additions & 6 deletions apps/web/src/lib/amount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,17 @@ export function parseAmount(raw: string, options: ParseAmountOptions = {}): Pars
return { value: null, isPartial: false, wasClamped: false }
}

const parsed = Number(normalized)
// Enforce decimal precision by truncating the string, not the float:
// Math.floor(0.57 * 1e7) / 1e7 yields 0.5699999 due to binary rounding.
const [intPart, fracPart = ""] = normalized.split(".")
const truncatedFrac = fracPart.slice(0, decimals)
const truncated = Number(truncatedFrac ? `${intPart}.${truncatedFrac}` : intPart)

// Guard: NaN or Infinity shouldn't happen with the regex above, but be safe
if (!Number.isFinite(parsed)) {
if (!Number.isFinite(truncated)) {
return { value: null, isPartial: false, wasClamped: false }
}

// Enforce decimal precision — truncate excess digits
const factor = 10 ** decimals
const truncated = Math.floor(parsed * factor) / factor

// Clamp to maxAmount if provided
let finalValue = truncated
let wasClamped = false
Expand Down
Loading