Skip to content

Commit

Permalink
Merge pull request #1127 from layerswap/dev-pending-swaps-newUI
Browse files Browse the repository at this point in the history
Implement vaul modal
  • Loading branch information
babkenmes authored Nov 5, 2024
2 parents 04ef4a1 + f187c9c commit f4aad2f
Show file tree
Hide file tree
Showing 18 changed files with 651 additions and 491 deletions.
55 changes: 0 additions & 55 deletions components/LayerswapMenu/WizardComponents/History.tsx

This file was deleted.

7 changes: 5 additions & 2 deletions components/LayerswapMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { MenuIcon, ChevronLeft } from "lucide-react";
import { FC, useState } from "react";
import Modal from "../../components/modal/modal";
import IconButton from "../buttons/iconButton";
import HistoryWizard from "./WizardComponents/History";
import { FormWizardProvider, useFormWizardaUpdate, useFormWizardState } from "../../context/formWizardProvider";
import { MenuStep } from "../../Models/Wizard";
import MenuList from "./MenuList";
import Wizard from "../Wizard/Wizard";
import WizardItem from "../Wizard/WizardItem";
import { NextRouter, useRouter } from "next/router";
import { resolvePersistantQueryParams } from "../../helpers/querryHelper";
import HistoryList from "../SwapHistory/History";

const Comp = () => {
const router = useRouter();
Expand All @@ -26,6 +26,7 @@ const Comp = () => {
clearMenuPath(router)
}
}
const goBackToMenuStep = () => { goToStep(MenuStep.Menu, "back"); clearMenuPath(router) }

const handleGoToStep = (step: MenuStep, path: string) => {
goToStep(step)
Expand Down Expand Up @@ -63,7 +64,9 @@ const Comp = () => {
<WizardItem StepName={MenuStep.Menu}>
<MenuList goToStep={handleGoToStep} />
</WizardItem>
<HistoryWizard setModalOpenState={setOpenTopModal} />
<WizardItem StepName={MenuStep.Transactions} GoBack={goBackToMenuStep} className="h-full">
<HistoryList onNewTransferClick={() => handleModalOpenStateChange(false)}/>
</WizardItem>
</Wizard>
</Modal>
</>
Expand Down
1 change: 0 additions & 1 deletion components/Swap/Form/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import { ImtblPassportProvider } from "../../WalletProviders/ImtblPassportProvid
import { Exchange, ExchangeToken } from "../../../Models/Exchange";
import { resolveRoutesURLForSelectedToken } from "../../../helpers/routes";
import { useValidationContext } from "../../../context/validationErrorContext";
import { toHex } from "viem";

type Props = {
partner?: Partner,
Expand Down
2 changes: 1 addition & 1 deletion components/Swap/Withdraw/Wallet/StarknetWalletWithdraw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const StarknetWalletWithdrawStep: FC<WithdrawPageProps> = ({ network, token, cal

const [loading, setLoading] = useState(false)
const [transferDone, setTransferDone] = useState<boolean>()
const { getWithdrawalProvider: getProvider, connectWallet } = useWallet()
const { getWithdrawalProvider: getProvider } = useWallet()
const { userId } = useAuthState()
const { setSwapTransaction } = useSwapTransactionStore();

Expand Down
82 changes: 82 additions & 0 deletions components/SwapHistory/Header.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { useRouter } from "next/router"
import { useCallback, useEffect, useRef, useState } from "react"
import HeaderWithMenu from "../HeaderWithMenu";
import { resolvePersistantQueryParams } from "../../helpers/querryHelper";
import { motion } from "framer-motion";

const Header = () => {

const router = useRouter();

const goBack = useCallback(() => {
window?.['navigation']?.['canGoBack'] ?
router.back()
: router.push({
pathname: "/",
query: resolvePersistantQueryParams(router.query)
})
}, [router])
const [height, setHeight] = useState(0)
const ref = useRef<HTMLDivElement>(null)

useEffect(() => {
setHeight(Number(ref?.current?.clientHeight))
}, [])

const handleAnimationEnd = (variant) => {
if (variant == "center") {
setHeight(Number(ref?.current?.clientHeight))
}
}
return <>
<motion.div
onAnimationComplete={handleAnimationEnd}
ref={ref}
transition={{
duration: 0.15,
}}
custom={{ direction: -1, width: 100 }}
variants={variants}
className={`text-primary-text text-base
max-sm:fixed
max-sm:inset-x-0
max-sm:top-0
max-sm:z-30
max-sm:bg-secondary-900
max-sm:shadow-widget-footer
max-sm:w-full`}>
<HeaderWithMenu goBack={goBack} />
</motion.div>
<div style={{ height: `${height}px` }}
className={`text-primary-text text-base
max-sm:inset-x-0
max-sm:bottom-0
max-sm:p-4 max-sm:w-full invisible sm:hidden`}>
</div>
</>

}

const variants = {
enter: () => {
return ({
opacity: 0,
y: '-100%',
})
},
center: () => {
return ({
opacity: 1,
y: 0,
})
},
exit: () => {
return ({
y: '-100%',
zIndex: 0,
opacity: 0,
})
},
};

export default Header;
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
import LayerSwapApiClient, { SwapResponse } from "../../../lib/layerSwapApiClient"
import { ApiResponse, EmptyApiResponse } from "../../../Models/ApiResponse"
import LayerSwapApiClient, { SwapResponse } from "../../lib/layerSwapApiClient"
import { ApiResponse, EmptyApiResponse } from "../../Models/ApiResponse"
import { ChevronDown, Plus, RefreshCw } from 'lucide-react'
import { FC, useCallback, useMemo, useState } from "react"
import HistorySummary from "../HistorySummary";
import HistorySummary from "./HistorySummary";
import useSWRInfinite from 'swr/infinite'
import useWallet from "../../../hooks/useWallet"
import useWallet from "../../hooks/useWallet"
import Link from "next/link"
import Snippet, { HistoryItemSceleton } from "./Snippet"
import { groupBy } from "../../utils/groupBy"
import { useAuthState, UserType } from "../../../context/authContext"
import ConnectButton from "../../buttons/connectButton"
import { FormWizardProvider } from "../../../context/formWizardProvider"
import { TimerProvider } from "../../../context/timerContext"
import GuestCard from "../../guestCard"
import { AuthStep } from "../../../Models/Wizard"
import { useHistoryContext } from "../../../context/historyContext"
import { groupBy } from "../utils/groupBy"
import { useAuthState, UserType } from "../../context/authContext"
import ConnectButton from "../buttons/connectButton"
import { FormWizardProvider } from "../../context/formWizardProvider"
import { TimerProvider } from "../../context/timerContext"
import GuestCard from "../guestCard"
import { AuthStep } from "../../Models/Wizard"
import React from "react"
import { useVirtualizer } from '@tanstack/react-virtual'
import Modal from "../../modal/modal";
import SwapDetails from "../SwapDetailsComponent"
import { addressFormat } from "../../../lib/address/formatter";
import { useSettingsState } from "../../../context/settings";
import SwapDetails from "./SwapDetailsComponent"
import { addressFormat } from "../../lib/address/formatter";
import { useSettingsState } from "../../context/settings";
import VaulDrawer from "../modal/vaul";

const PAGE_SIZE = 20
type ListProps = {
statuses?: string | number;
refreshing?: boolean;
loadExplorerSwaps: boolean;
componentType?: 'steps' | 'page'
onSwapSettled?: () => void,
onNewTransferClick?: () => void
}

Expand All @@ -42,17 +38,19 @@ const getSwapsKey = () => (index: number, statuses: Status[], addresses?: string

type Swap = SwapResponse & { type: 'user' | 'explorer' }

const HistoryList: FC<ListProps> = ({ componentType = 'page', onSwapSettled, onNewTransferClick }) => {
const HistoryList: FC<ListProps> = ({ onNewTransferClick }) => {
const { networks } = useSettingsState()
const [openSwapDetailsModal, setOpenSwapDetailsModal] = useState(false)
const [showAll, setShowAll] = useState(false)
const { wallets } = useWallet()
const { userId } = useAuthState()
const [selectedSwap, setSelectedSwap] = useState<Swap | null>(null)

const addresses = wallets.map(w => {
const network = networks.find(n => n.chain_id == w.chainId)
return addressFormat(w.address, network || null)
})
const { setSelectedSwap, selectedSwap } = useHistoryContext()

const handleopenSwapDetails = (swap: Swap) => {
setSelectedSwap(swap)
setOpenSwapDetailsModal(true)
Expand Down Expand Up @@ -126,7 +124,7 @@ const HistoryList: FC<ListProps> = ({ componentType = 'page', onSwapSettled, onN
const items = rowVirtualizer.getVirtualItems()
if ((userSwapsLoading && !(Number(userSwaps?.length) > 0))) return <Snippet />
if (!wallets.length && !userId) return <ConnectOrSignIn onLogin={() => { mutate(); mutatePendingSwaps(); }} />
if (!list.length) return <BlankHistory componentType={componentType} onNewTransferClick={onNewTransferClick} onLogin={() => { mutate(); mutatePendingSwaps(); }} />
if (!list.length) return <BlankHistory onNewTransferClick={onNewTransferClick} onLogin={() => { mutate(); mutatePendingSwaps(); }} />

return (
<div className="relative">
Expand Down Expand Up @@ -226,31 +224,28 @@ const HistoryList: FC<ListProps> = ({ componentType = 'page', onSwapSettled, onN
</div>
</div>
</div>
{
<Modal
height="80%"
show={openSwapDetailsModal}
setShow={handleSWapDetailsShow}
header='Swap details'
modalId="swapDetails"
>
{
selectedSwap &&
<SwapDetails swapResponse={selectedSwap} />
}
</Modal>
}
<VaulDrawer
show={openSwapDetailsModal}
setShow={handleSWapDetailsShow}
header='Swap details'
modalId="swapDetails"
snapPointsCount={2}
>
{
selectedSwap &&
<SwapDetails swapResponse={selectedSwap} />
}
</VaulDrawer>
</div>
)
}

type BlankHistoryProps = {
componentType?: 'steps' | 'page',
onNewTransferClick?: () => void,
onLogin: () => void
}

const BlankHistory = ({ componentType, onNewTransferClick, onLogin }: BlankHistoryProps) => {
const BlankHistory = ({ onNewTransferClick, onLogin }: BlankHistoryProps) => {

return <div className="w-full h-[70vh] sm:h-full min-h-[inherit] flex flex-col justify-between items-center ">
<div />
Expand All @@ -265,18 +260,10 @@ const BlankHistory = ({ componentType, onNewTransferClick, onLogin }: BlankHisto
Transfers you make with this wallet/account will appear here after excution.
</p>
</div>
{
componentType === 'steps' ?
<button onClick={onNewTransferClick} className="mt-10 flex items-center gap-2 text-base text-secondary-text font-normal bg-secondary-500 hover:bg-secondary-600 py-2 px-3 rounded-lg">
<Plus className="w-4 h-4" />
<p>New Transfer</p>
</button>
:
<Link href={"/"} className="mt-10 flex items-center gap-2 text-base text-secondary-text font-normal bg-secondary-500 hover:bg-secondary-600 py-2 px-3 rounded-lg">
<Plus className="w-4 h-4" />
<p>New Transfer</p>
</Link>
}
<Link onClick={onNewTransferClick} href={"/"} className="mt-10 flex items-center gap-2 text-base text-secondary-text font-normal bg-secondary-500 hover:bg-secondary-600 py-2 px-3 rounded-lg">
<Plus className="w-4 h-4" />
<p>New Transfer</p>
</Link>

</div>
<div className="w-full">
Expand Down Expand Up @@ -351,14 +338,6 @@ function resolveDate(dateInput) {
// Convert the time difference from milliseconds to days
const dayDiff = Math.floor(timeDiff / (1000 * 3600 * 24));

// Format the input date to DD/MM/YYYY
const formatDate = (date) => {
const day = ("0" + date.getDate()).slice(-2);
const month = ("0" + (date.getMonth() + 1)).slice(-2);
const year = date.getFullYear();
return `${day}/${month}/${year}`;
}

// Resolve the output based on the difference in days
switch (dayDiff) {
case 0:
Expand All @@ -377,7 +356,7 @@ function resolveDate(dateInput) {
return "6 days ago";
default:
// If the date is more than 6 days ago, return it in DD/MM/YYYY format
return formatDate(inputDate);
return dateInput;
}
}

Expand Down
Loading

0 comments on commit f4aad2f

Please sign in to comment.