diff --git a/web/components/add-funds-button.tsx b/web/components/add-funds-button.tsx deleted file mode 100644 index b610bfee..00000000 --- a/web/components/add-funds-button.tsx +++ /dev/null @@ -1,84 +0,0 @@ -import clsx from 'clsx' -import { useEffect, useState } from 'react' - -import { useUser } from 'web/hooks/use-user' -import { checkoutURL } from 'web/lib/service/stripe' -import { FundsSelector } from './yes-no-selector' - -export function AddFundsButton(props: { className?: string }) { - const { className } = props - const user = useUser() - - const [amountSelected, setAmountSelected] = useState<1000 | 2500 | 10000>( - 2500 - ) - - const location = useLocation() - - return ( - <> - - - -
-
-
Get Mana
- -
- Buy mana (M$) to trade in your favorite markets.
(Not - redeemable for cash.) -
- -
Amount
- - -
-
Price USD
-
- ${Math.round(amountSelected / 100)}.00 -
-
- -
- - -
- -
-
-
-
- - ) -} - -// needed in next js -// window not loaded at runtime -const useLocation = () => { - const [href, setHref] = useState('') - useEffect(() => { - setHref(window.location.href) - }, []) - return href -} diff --git a/web/components/add-funds-modal.tsx b/web/components/add-funds-modal.tsx new file mode 100644 index 00000000..cac21f96 --- /dev/null +++ b/web/components/add-funds-modal.tsx @@ -0,0 +1,58 @@ +import { manaToUSD } from 'common/util/format' +import { useState } from 'react' +import { useUser } from 'web/hooks/use-user' +import { checkoutURL } from 'web/lib/service/stripe' +import { Button } from './button' +import { Modal } from './layout/modal' +import { FundsSelector } from './yes-no-selector' + +export function AddFundsModal(props: { + open: boolean + setOpen(open: boolean): void +}) { + const { open, setOpen } = props + + const user = useUser() + + const [amountSelected, setAmountSelected] = useState<1000 | 2500 | 10000>( + 2500 + ) + + return ( + +
Get Mana
+ +
+ Buy mana (M$) to trade in your favorite markets.
(Not redeemable + for cash.) +
+ +
Amount
+ + +
+
Price USD
+
{manaToUSD(amountSelected)}
+
+ +
+ + +
+ +
+
+
+ ) +} diff --git a/web/components/amount-input.tsx b/web/components/amount-input.tsx index 45c73c5e..65a79c20 100644 --- a/web/components/amount-input.tsx +++ b/web/components/amount-input.tsx @@ -1,11 +1,11 @@ import clsx from 'clsx' -import React from 'react' +import React, { useState } from 'react' import { useUser } from 'web/hooks/use-user' import { formatMoney } from 'common/util/format' import { Col } from './layout/col' -import { SiteLink } from './site-link' import { ENV_CONFIG } from 'common/envs/constants' import { Row } from './layout/row' +import { AddFundsModal } from './add-funds-modal' export function AmountInput(props: { amount: number | undefined @@ -35,6 +35,8 @@ export function AmountInput(props: { onChange(isInvalid ? undefined : amount) } + const [addFundsModalOpen, setAddFundsModalOpen] = useState(false) + return ( <> @@ -66,9 +68,16 @@ export function AmountInput(props: { {error === 'Insufficient balance' ? ( <> Not enough funds. - - Buy more? - + + ) : ( error diff --git a/web/pages/create.tsx b/web/pages/create.tsx index 03b90d7c..e7c2a1b8 100644 --- a/web/pages/create.tsx +++ b/web/pages/create.tsx @@ -36,6 +36,8 @@ import { MultipleChoiceAnswers } from 'web/components/answers/multiple-choice-an import { MINUTE_MS } from 'common/util/time' import { ExternalLinkIcon } from '@heroicons/react/outline' import { SiteLink } from 'web/components/site-link' +import { Button } from 'web/components/button' +import { AddFundsModal } from 'web/components/add-funds-modal' export const getServerSideProps = redirectIfLoggedOut('/', async (_, creds) => { return { props: { auth: await getUserAndPrivateUser(creds.uid) } } @@ -168,6 +170,8 @@ export function NewContract(props: { const [showGroupSelector, setShowGroupSelector] = useState(true) const [visibility, setVisibility] = useState('public') + const [fundsModalOpen, setFundsModalOpen] = useState(false) + const closeTime = closeDate ? dayjs(`${closeDate}T${closeHoursMinutes}`).valueOf() : undefined @@ -507,12 +511,17 @@ export function NewContract(props: { {ante > balance && !deservesFreeMarket && (
Insufficient balance - + +
)} diff --git a/web/pages/profile.tsx b/web/pages/profile.tsx index 5773f30f..637ad518 100644 --- a/web/pages/profile.tsx +++ b/web/pages/profile.tsx @@ -1,11 +1,9 @@ import { RefreshIcon } from '@heroicons/react/outline' import { PrivateUser, User } from 'common/user' import { cleanDisplayName, cleanUsername } from 'common/util/clean-username' -import { formatMoney } from 'common/util/format' import Link from 'next/link' import React, { useState } from 'react' import Textarea from 'react-expanding-textarea' -import { AddFundsButton } from 'web/components/add-funds-button' import { ConfirmationButton } from 'web/components/confirmation-button' import { Col } from 'web/components/layout/col' import { Row } from 'web/components/layout/row' @@ -198,14 +196,6 @@ export default function ProfilePage(props: { -
- - - {formatMoney(user.balance)} - - -
-