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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
13 changes: 8 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

# dependencies
*node_modules
dist/
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
*.next/
/out/
next-env.d.ts

# production
/build
Expand All @@ -34,11 +34,14 @@ yarn-error.log*

# Moving to yarn
package-lock.json
storybook-static/*

# Sentry Config File
.sentryclirc
.env*.local

pr-review-report.md
# typescript
*.tsbuildinfo
next-env.d.ts

tsconfig.tsbuildinfo
# PR Review Report
pr-review-report.md
10 changes: 10 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
auto-install-peers=false
strict-peer-dependencies=true
prefer-workspace-packages=true
public-hoist-pattern[]=react
public-hoist-pattern[]=react-*
public-hoist-pattern[]=wagmi
public-hoist-pattern[]=@wagmi/*
public-hoist-pattern[]=viem
public-hoist-pattern[]=@tanstack/react-query
public-hoist-pattern[]=@tanstack/query-core
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion Models/Balance.ts → apps/app/Models/Balance.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Network, Token } from "./Network"
import { Wallet } from "./WalletProvider"
import { NodeErrorCategory } from "@/lib/balances/nodeErrorClassifier"
import { NodeErrorCategory } from "@/apps/app/lib/balances/nodeErrorClassifier"

export type GasProps = {
network: Network,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TokenBalance } from "./Balance";
import { Network, Token } from "./Network";
import { extractErrorDetails } from "@/lib/balances/errorUtils";
import { classifyNodeError } from "@/lib/balances/nodeErrorClassifier";
import { extractErrorDetails } from "@/apps/app/lib/balances/errorUtils";
import { classifyNodeError } from "@/apps/app/lib/balances/nodeErrorClassifier";

export abstract class BalanceProvider {
abstract supportsNetwork: (network: Network) => boolean
Expand Down
2 changes: 2 additions & 0 deletions apps/app/Models/HTLCStatus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Re-exported from @train-protocol/sdk — single source of truth
export { HTLCStatus, TERMINAL_STATUSES, isTerminalStatus } from '@train-protocol/sdk'
13 changes: 13 additions & 0 deletions apps/app/Models/Network.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Re-exported from @train-protocol/sdk — single source of truth
export {
NetworkContractType,
Network,
Token,
getNativeToken,
} from '@train-protocol/sdk'
export type {
NetworkTypeInfo,
NetworkNode,
NetworkContract,
ExplorerUrlTemplate,
} from '@train-protocol/sdk'
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 0 additions & 13 deletions Models/WalletProvider.ts → apps/app/Models/WalletProvider.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import { WalletAccount } from 'starknet';
import { ClaimParams, LockParams, CreateHTLCParams, RefundParams } from './phtlc';
import { LockDetails } from './phtlc/PHTLC';
import { RecoveredSwapData } from '@/lib/wallets/utils/atomicTypes';

export type InternalConnector = {
name: string,
Expand Down Expand Up @@ -67,16 +64,6 @@ export type WalletProvider = {
providerIcon?: string,
unsupportedPlatforms?: string[],
ready: boolean,
} & AtmoicFunctions

export type AtmoicFunctions = {
createHTLC: (args: CreateHTLCParams) => Promise<{ hash: string, hashlock: string } | null | undefined>,
claim: (args: ClaimParams) => Promise<string | undefined> | undefined | void,
refund: (args: RefundParams) => Promise<any> | undefined | void,
getUserLockDetails: (args: LockParams) => Promise<LockDetails | null>,
secureGetDetails?: (args: LockParams) => Promise<LockDetails | null>,
getSolverLockDetails?: (args: LockParams) => Promise<LockDetails | null>
recoverSwap?: (txHash: string, chainId: string) => Promise<RecoveredSwapData>
}

export type SelectAccountProps = {
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions apps/app/Models/phtlc/PHTLC.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Re-exported from @train-protocol/sdk — single source of truth
export { LockStatus } from '@train-protocol/sdk'
export type { LockDetails } from '@train-protocol/sdk'
9 changes: 9 additions & 0 deletions apps/app/Models/phtlc/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Re-exported from @train-protocol/sdk — single source of truth
export type {
CreateHTLCParams,
LockParams,
OldLockParams,
RefundParams,
ClaimParams,
GetCommitsParams,
} from '@train-protocol/sdk'
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Jazzicon from "@metamask/jazzicon";
import { FC, useEffect, useRef } from "react";
import { Address } from "@/lib/address";
import { Address } from "@/apps/app/lib/address";

type Props = {
address: string;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState } from "react"
import { ArrowRight } from "lucide-react"
import { truncateDecimals } from "../utils/RoundDecimals"
import { Token } from "@/Models/Network"
import { Token } from "@/apps/app/Models/Network"

export const RateElement = ({
fromAsset,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { FC } from "react";
import { Token } from "../../Models/Network";
import { SwapQuote } from "../../lib/trainApiClient";
import { truncateDecimals } from "../utils/RoundDecimals";
import formatAmount from "@/lib/formatAmount";
import formatAmount from "@/apps/app/lib/formatAmount";

type WillReceiveProps = {
destination_token: Token | undefined;
Expand All @@ -13,9 +13,8 @@ type WillReceiveProps = {
export const ReceiveAmounts: FC<WillReceiveProps> = ({ source_token, destination_token, fee, isFeeLoading }) => {

const receive_amount_in_base_units = fee?.receiveAmount
const receive_amount = formatAmount(receive_amount_in_base_units, destination_token?.decimals);
const parsedReceiveAmount = truncateDecimals(receive_amount ?? 0, destination_token?.decimals);

const receive_amount = destination_token ? formatAmount(BigInt(receive_amount_in_base_units ?? 0), destination_token?.decimals) : null;
const parsedReceiveAmount = receive_amount ? truncateDecimals(Number(receive_amount), destination_token?.decimals) : null;

return <div className="w-full h-full">
<div className="flex items-center justify-between w-full">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { FC, useMemo } from 'react'
import { Tooltip, TooltipContent, TooltipTrigger } from '../../shadcn/tooltip'
import { RateElement } from '../Rate'
import { SwapQuote } from '@/lib/trainApiClient'
import { SwapQuote } from '@/apps/app/lib/trainApiClient'
import { SwapFormValues } from '../../DTOs/SwapFormValues'
import useWallet from '@/hooks/useWallet'
import useSWRGas from '@/lib/gases/useSWRGas'
import { resolveTokenUsdPrice } from '@/helpers/tokenHelper'
import formatAmount from '@/lib/formatAmount'
import { truncateDecimals } from '@/components/utils/RoundDecimals'
import useWallet from '@/apps/app/hooks/useWallet'
import useSWRGas from '@/apps/app/lib/gases/useSWRGas'
import { resolveTokenUsdPrice } from '@/apps/app/helpers/tokenHelper'
import formatAmount from '@/apps/app/lib/formatAmount'
import { truncateDecimals } from '@/apps/app/components/utils/RoundDecimals'

type DetailedEstimatesProps = {
quote: SwapQuote | undefined,
Expand Down Expand Up @@ -81,22 +81,22 @@ const Fees = ({ quote, values }: { quote: SwapQuote | undefined, values: SwapFor

const fee_amount = useMemo(() => {
if (!quote?.totalFee || !fromCurrency) return null
return formatAmount(quote.totalFee, fromCurrency.decimals)
return formatAmount(BigInt(quote.totalFee), fromCurrency.decimals)
}, [quote?.totalFee, fromCurrency])

const feeInUsd = useMemo(() => {
if (fee_amount === null || fee_amount === undefined) return null
const priceInUsd = resolveTokenUsdPrice(fromCurrency)
if (!priceInUsd) return null
return fee_amount * priceInUsd
return Number(fee_amount) * priceInUsd
}, [fee_amount, fromCurrency, quote])

const displayFeeInUsd = feeInUsd != null
? (feeInUsd === 0 ? 'Free' : feeInUsd < 0.01 ? '<$0.01' : `$${feeInUsd.toFixed(2)}`)
: null

const displayFee = fee_amount !== null && fee_amount !== undefined
? (fee_amount === 0 ? 'Free' : truncateDecimals(fee_amount, Math.min(fromCurrency?.decimals || 8, 8)))
? (Number(fee_amount) === 0 ? 'Free' : truncateDecimals(Number(fee_amount), Math.min(fromCurrency?.decimals || 8, 8)))
: undefined

const currencyName = fromCurrency?.symbol || ''
Expand Down Expand Up @@ -130,9 +130,9 @@ const Rate = ({ quote, values }: { quote: SwapQuote | undefined, values: SwapFor
if (!quote?.receiveAmount || !values.amount || !fromAsset || !toAsset) return null
const sendAmount = parseFloat(values.amount)
if (!sendAmount || sendAmount === 0) return null
const receiveAmount = formatAmount(quote.receiveAmount, toAsset.decimals)
if (!receiveAmount || receiveAmount === 0) return null
return receiveAmount / sendAmount
const receiveAmount = toAsset ? formatAmount(BigInt(quote.receiveAmount), toAsset.decimals) : null
if (!receiveAmount || Number(receiveAmount) === 0) return null
return Number(receiveAmount) / sendAmount
}, [quote?.receiveAmount, values.amount, fromAsset, toAsset])

if (!fromAsset || !toAsset || !rate) return null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { FC, useMemo } from 'react'
import { ChevronDown } from 'lucide-react'
import AddressIcon from '../../AddressIcon'
import { Address } from "@/lib/address";
import { Wallet } from '@/Models/WalletProvider'
import { SwapFormValues } from '@/components/DTOs/SwapFormValues'
import { ExtendedAddress } from '@/components/Input/Address/AddressPicker/AddressWithIcon'
import { Address } from "@/apps/app/lib/address";
import { Wallet } from '@/apps/app/Models/WalletProvider'
import { SwapFormValues } from '@/apps/app/components/DTOs/SwapFormValues'
import { ExtendedAddress } from '@/apps/app/components/Input/Address/AddressPicker/AddressWithIcon'
import { DetailsButton } from '..'
import { SwapQuote } from '@/lib/trainApiClient'
import { SwapQuote } from '@/apps/app/lib/trainApiClient'
import clsx from 'clsx'
import { GasFee } from './DetailedEstimates'
import NumberFlow from '@number-flow/react'
import { Partner } from '@/Models/Partner'
import { useQueryState } from '@/context/query'
import { ImageWithFallback } from '@/components/Common/ImageWithFallback'
import { Partner } from '@/apps/app/Models/Partner'
import { useQueryState } from '@/apps/app/context/query'
import { ImageWithFallback } from '@/apps/app/components/Common/ImageWithFallback'

export const SummaryRow: FC<{
isQuoteLoading?: boolean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { FC, useState } from 'react'
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '../../shadcn/accordion'
import { ChevronDown } from 'lucide-react'
import { SwapQuote } from '@/lib/trainApiClient'
import { SwapQuote } from '@/apps/app/lib/trainApiClient'
import { SwapFormValues } from '../../DTOs/SwapFormValues'
import { SummaryRow } from './SummaryRow'
import { DetailedEstimates } from './DetailedEstimates'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import { FC, useMemo, useState } from 'react';
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '../shadcn/accordion';
import clsx from 'clsx';
import { ChevronDown } from 'lucide-react';
import { SwapQuote } from '@/lib/trainApiClient';
import { SwapQuote } from '@/apps/app/lib/trainApiClient';
import GasIcon from '../Icons/GasIcon';
import Clock from '../Icons/Clock';
import AverageCompletionTime from '../Common/AverageCompletionTime';
import useWallet from '@/hooks/useWallet';
import useSWRGas from '@/lib/gases/useSWRGas';
import useWallet from '@/apps/app/hooks/useWallet';
import useSWRGas from '@/apps/app/lib/gases/useSWRGas';
import NumberFlow from '@number-flow/react';
import { resolveTokenUsdPrice } from '@/helpers/tokenHelper';
import { resolveTokenUsdPrice } from '@/apps/app/helpers/tokenHelper';
import { DetailedEstimates } from './SwapQuote/DetailedEstimates';
import formatAmount from '@/lib/formatAmount';
import formatAmount from '@/apps/app/lib/formatAmount';
import { truncateDecimals } from '../utils/RoundDecimals';

export interface QuoteComponentProps {
Expand Down Expand Up @@ -75,22 +75,22 @@ export const DetailsButton: FC<QuoteComponentProps> = ({ quote, isQuoteLoading,
const fromCurrency = values.fromCurrency
const feeAmount = useMemo(() => {
if (!quote?.totalFee || !fromCurrency) return null
return formatAmount(quote.totalFee, fromCurrency.decimals)
return formatAmount(BigInt(quote.totalFee), fromCurrency.decimals)
}, [quote?.totalFee, fromCurrency])

const feeInUsd = useMemo(() => {
if (feeAmount === null || feeAmount === undefined) return null
const priceInUsd = resolveTokenUsdPrice(fromCurrency)
if (!priceInUsd) return null
return feeAmount * priceInUsd
return Number(feeAmount) * priceInUsd
}, [feeAmount, fromCurrency, quote])

const displayFeeInUsd = feeInUsd != null
? (feeInUsd === 0 ? 'Free' : feeInUsd < 0.01 ? '<$0.01' : `$${feeInUsd.toFixed(2)}`)
: null

const displayFee = feeAmount !== null && feeAmount !== undefined
? (feeAmount === 0 ? 'Free' : `${truncateDecimals(feeAmount, Math.min(fromCurrency?.decimals || 8, 8))} ${fromCurrency?.symbol || ''}`)
? (Number(feeAmount) === 0 ? 'Free' : `${truncateDecimals(Number(feeAmount), Math.min(fromCurrency?.decimals || 8, 8))} ${fromCurrency?.symbol || ''}`)
: null

// Train doesn't have avg_completion_time yet
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import IconButton from "@/components/buttons/iconButton"
import GoHomeButton from "@/components/utils/GoHome"
import IconButton from "@/apps/app/components/buttons/iconButton"
import GoHomeButton from "@/apps/app/components/utils/GoHome"
import { ArrowLeft } from 'lucide-react'
import TrainMenu from "@/components/TrainMenu"
import { useQueryState } from "@/context/query"
import TrainMenu from "@/apps/app/components/TrainMenu"
import { useQueryState } from "@/apps/app/context/query"
import { UserStatusHeader } from "../SecretDerivation"
import useWindowDimensions from "@/hooks/useWindowDimensions"
import useWindowDimensions from "@/apps/app/hooks/useWindowDimensions"
import dynamic from "next/dynamic"
import PendingSwap from "../Swap/PendingSwap"

const WalletsHeader = dynamic(() => import("../Wallet/ConnectedWallets.tsx").then((comp) => comp.WalletsHeader), {
const WalletsHeader = dynamic(() => import("../Wallet/ConnectedWallets").then((comp) => comp.WalletsHeader), {
loading: () => <></>
})

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import Link from "next/link"
import AddressIcon from "../../AddressIcon"
import { SwapFormValues } from "../../DTOs/SwapFormValues"
import { Partner } from "../../../Models/Partner"
import { Address, getExplorerUrl } from "@/lib/address"
import NetworkSettings from "@/lib/NetworkSettings"
import { Address, getExplorerUrl } from "@/apps/app/lib/address"
import NetworkSettings from "@/apps/app/lib/NetworkSettings"

type AddressNoteModalProps = {
partner: Partner | undefined;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { CommandGroup, CommandList, CommandWrapper } from "@/components/shadcn/command";
import { Address } from "@/lib/address";
import FilledCheck from "@/components/Icons/FilledCheck";
import { CommandGroup, CommandList, CommandWrapper } from "@/apps/app/components/shadcn/command";
import { Address } from "@/apps/app/lib/address";
import FilledCheck from "@/apps/app/components/Icons/FilledCheck";
import { AddressGroup, AddressItem } from ".";
import { Network } from "@/Models/Network";
import { Network } from "@/apps/app/Models/Network";
import { FC } from "react";
import AddressWithIcon from "./AddressWithIcon";
import { Partner } from "@/Models/Partner";
import { Wallet } from "@/Models/WalletProvider";
import { Partner } from "@/apps/app/Models/Partner";
import { Wallet } from "@/apps/app/Models/WalletProvider";
import { BookOpen } from "lucide-react";

type AddressBookProps = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { FC } from "react"
import { AddressItem } from ".";
import { Partner } from "@/Models/Partner";
import { Network } from "@/Models/Network";
import { Wallet } from "@/Models/WalletProvider";
import { Partner } from "@/apps/app/Models/Partner";
import { Network } from "@/apps/app/Models/Network";
import { Wallet } from "@/apps/app/Models/WalletProvider";

type AddressButtonProps = {
openAddressModal: () => void;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { FC, MouseEventHandler, ReactNode, SVGProps, useCallback, useMemo, useState } from "react"
import { AddressGroup, AddressItem } from ".";
import AddressIcon from "@/components//AddressIcon";
import { Address, getExplorerUrl } from "@/lib/address";
import AddressIcon from "@/apps/app/components/AddressIcon";
import { Address, getExplorerUrl } from "@/apps/app/lib/address";
import { History, Copy, Check, ChevronDown, WalletIcon, Pencil, Link2, SquareArrowOutUpRight, Unplug, Info } from "lucide-react";
import { Partner } from "@/Models/Partner";
import { Network } from "@/Models/Network";
import { Popover, PopoverContent, PopoverTrigger } from "@/components//shadcn/popover";
import useCopyClipboard from "@/hooks/useCopyClipboard";
import { Partner } from "@/apps/app/Models/Partner";
import { Network } from "@/apps/app/Models/Network";
import { Popover, PopoverContent, PopoverTrigger } from "@/apps/app/components/shadcn/popover";
import useCopyClipboard from "@/apps/app/hooks/useCopyClipboard";
import Link from "next/link";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components//shadcn/tooltip";
import { ImageWithFallback } from "@/components/Common/ImageWithFallback";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/apps/app/components/shadcn/tooltip";
import { ImageWithFallback } from "@/apps/app/components/Common/ImageWithFallback";
import clsx from "clsx";
import shortenString from "@/components/utils/ShortenString";
import NetworkSettings from "@/lib/NetworkSettings";
import shortenString from "@/apps/app/components/utils/ShortenString";
import NetworkSettings from "@/apps/app/lib/NetworkSettings";

type Props = {
addressItem: AddressItem;
Expand Down
Loading