-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4d4291b
commit 9120b77
Showing
10 changed files
with
270 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
"use client" | ||
import { useEffect, useState } from "react" | ||
|
||
import { gql } from "@apollo/client" | ||
|
||
import { useSession } from "next-auth/react" | ||
|
||
import CreatePageAmount from "@/components/create/create-page-amount" | ||
import CreatePagePercentage from "@/components/create/create-page-percentage" | ||
import { getWalletDetails } from "@/utils/helpers" | ||
import ConfirmModal from "@/components/create/confirm-modal" | ||
import { useCurrency } from "@/context/currency-context" | ||
import { useCurrencyConversionEstimationQuery } from "@/lib/graphql/generated" | ||
import { amountCalculator } from "@/lib/amount-calculator" | ||
import { convertCurrency } from "@/lib/utils" | ||
|
||
gql` | ||
mutation CreateWithdrawLink($input: CreateWithdrawLinkInput!) { | ||
createWithdrawLink(input: $input) { | ||
commissionPercentage | ||
createdAt | ||
id | ||
identifierCode | ||
salesAmountInCents | ||
status | ||
uniqueHash | ||
userId | ||
voucherAmountInCents | ||
voucherSecret | ||
paidAt | ||
} | ||
} | ||
` | ||
|
||
gql` | ||
query CurrencyConversionEstimation($amount: Float!, $currency: DisplayCurrency!) { | ||
currencyConversionEstimation(amount: $amount, currency: $currency) { | ||
btcSatAmount | ||
id | ||
usdCentAmount | ||
timestamp | ||
} | ||
} | ||
` | ||
|
||
type Props = { | ||
platformFeesInPpm: number | ||
} | ||
|
||
export default function CreatePage({ platformFeesInPpm }: Props) { | ||
const session = useSession() | ||
const { currency } = useCurrency() | ||
|
||
const storedCommission = | ||
typeof window !== "undefined" ? localStorage.getItem("commission") : null | ||
const [commissionPercentage, setCommissionPercentage] = useState<string>( | ||
storedCommission || "0", | ||
) | ||
|
||
const [amount, setAmount] = useState<string>("0") | ||
const [confirmModal, setConfirmModal] = useState<boolean>(false) | ||
const [currentPage, setCurrentPage] = useState<string>("AMOUNT") | ||
|
||
const { data: currencyConversion, refetch } = useCurrencyConversionEstimationQuery({ | ||
variables: { amount: Number(amount), currency }, | ||
context: { endpoint: "GALOY" }, | ||
pollInterval: 60000, | ||
}) | ||
|
||
useEffect(() => { | ||
refetch({ amount: Number(amount), currency }) | ||
}, [amount, currency, refetch]) | ||
|
||
const voucherAmountInCents = | ||
amountCalculator.voucherAmountAfterPlatformFeesAndCommission({ | ||
voucherPrice: currencyConversion?.currencyConversionEstimation.usdCentAmount, | ||
commissionPercentage: Number(commissionPercentage), | ||
platformFeesInPpm, | ||
}) | ||
|
||
const voucherAmountInDollars = convertCurrency.centsToUsd({ | ||
cents: voucherAmountInCents, | ||
}) | ||
|
||
if (!session?.data?.userData?.me?.defaultAccount.wallets) { | ||
return null | ||
} | ||
|
||
const { btcWallet, usdWallet } = getWalletDetails({ | ||
wallets: session?.data?.userData?.me?.defaultAccount?.wallets, | ||
}) | ||
|
||
if (!btcWallet || !usdWallet) { | ||
return null | ||
} | ||
|
||
if (currentPage === "AMOUNT") { | ||
return ( | ||
<div className="top_page_container"> | ||
<ConfirmModal | ||
open={confirmModal} | ||
onClose={() => setConfirmModal(false)} | ||
amount={amount} | ||
currency={currency} | ||
commissionPercentage={commissionPercentage} | ||
btcWallet={btcWallet} | ||
usdWallet={usdWallet} | ||
platformFeesInPpm={platformFeesInPpm} | ||
voucherAmountInDollars={voucherAmountInDollars} | ||
/> | ||
|
||
<CreatePageAmount | ||
amount={amount} | ||
currency={currency} | ||
setAmount={setAmount} | ||
setCurrentPage={setCurrentPage} | ||
setConfirmModal={setConfirmModal} | ||
commissionPercentage={commissionPercentage} | ||
voucherAmountInDollars={voucherAmountInDollars} | ||
/> | ||
</div> | ||
) | ||
} else { | ||
return ( | ||
<> | ||
<div className="top_page_container"> | ||
<CreatePagePercentage | ||
commissionPercentage={commissionPercentage} | ||
setCommissionPercentage={setCommissionPercentage} | ||
setCurrentPage={setCurrentPage} | ||
/> | ||
</div> | ||
</> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,105 +1,8 @@ | ||
"use client" | ||
import { useState } from "react" | ||
import CreatePage from "@/app/create/client-side-page" | ||
import { env } from "@/env" | ||
|
||
import { gql } from "@apollo/client" | ||
export default function Page() { | ||
const platformFeesInPpm = env.PLATFORM_FEES_IN_PPM | ||
|
||
import { useSession } from "next-auth/react" | ||
|
||
import CreatePageAmount from "@/components/create/create-page-amount" | ||
import CreatePagePercentage from "@/components/create/create-page-percentage" | ||
import { getWalletDetails } from "@/utils/helpers" | ||
import ConfirmModal from "@/components/create/confirm-modal" | ||
import { useCurrency } from "@/context/currency-context" | ||
|
||
gql` | ||
mutation CreateWithdrawLink($input: CreateWithdrawLinkInput!) { | ||
createWithdrawLink(input: $input) { | ||
commissionPercentage | ||
createdAt | ||
id | ||
identifierCode | ||
salesAmountInCents | ||
status | ||
uniqueHash | ||
userId | ||
voucherAmountInCents | ||
voucherSecret | ||
paidAt | ||
} | ||
} | ||
` | ||
|
||
gql` | ||
query CurrencyConversionEstimation($amount: Float!, $currency: DisplayCurrency!) { | ||
currencyConversionEstimation(amount: $amount, currency: $currency) { | ||
btcSatAmount | ||
id | ||
usdCentAmount | ||
timestamp | ||
} | ||
} | ||
` | ||
|
||
export default function CreatePage() { | ||
const session = useSession() | ||
const { currency } = useCurrency() | ||
const storedCommission = | ||
typeof window !== "undefined" ? localStorage.getItem("commission") : null | ||
|
||
const [commissionPercentage, setCommissionPercentage] = useState<string>( | ||
storedCommission || "0", | ||
) | ||
|
||
const [amount, setAmount] = useState<string>("0") | ||
const [confirmModal, setConfirmModal] = useState<boolean>(false) | ||
const [currentPage, setCurrentPage] = useState<string>("AMOUNT") | ||
|
||
if (!session?.data?.userData?.me?.defaultAccount.wallets) { | ||
return null | ||
} | ||
|
||
const { btcWallet, usdWallet } = getWalletDetails({ | ||
wallets: session?.data?.userData?.me?.defaultAccount?.wallets, | ||
}) | ||
|
||
if (!btcWallet || !usdWallet) { | ||
return null | ||
} | ||
|
||
if (currentPage === "AMOUNT") { | ||
return ( | ||
<div className="top_page_container"> | ||
<ConfirmModal | ||
open={confirmModal} | ||
onClose={() => setConfirmModal(false)} | ||
amount={amount} | ||
currency={currency} | ||
commissionPercentage={commissionPercentage} | ||
btcWallet={btcWallet} | ||
usdWallet={usdWallet} | ||
/> | ||
|
||
<CreatePageAmount | ||
amount={amount} | ||
currency={currency} | ||
setAmount={setAmount} | ||
setCurrentPage={setCurrentPage} | ||
setConfirmModal={setConfirmModal} | ||
commissionPercentage={commissionPercentage} | ||
/> | ||
</div> | ||
) | ||
} else { | ||
return ( | ||
<> | ||
<div className="top_page_container"> | ||
<CreatePagePercentage | ||
commissionPercentage={commissionPercentage} | ||
setCommissionPercentage={setCommissionPercentage} | ||
setCurrentPage={setCurrentPage} | ||
/> | ||
</div> | ||
</> | ||
) | ||
} | ||
return <CreatePage platformFeesInPpm={platformFeesInPpm} /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.