Skip to content

Commit 5b7107d

Browse files
authored
feat : APP-363 another user purchased credits modal (#2500)
1 parent aa7d3db commit 5b7107d

File tree

15 files changed

+690
-209
lines changed

15 files changed

+690
-209
lines changed

web-components/src/components/inputs/new/CustomSelect/CustomSelect.Placeholder.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export function Placeholder({
77
isOpen,
88
options,
99
selectedOption,
10-
OptionComponent,
10+
OptionComponent = () => <></>,
1111
ariaLabel,
1212
}: {
1313
setIsOpen: (isOpen: boolean) => void;
@@ -24,8 +24,8 @@ export function Placeholder({
2424
className="inline-flex justify-center w-full border-none px-4 py-2 bg-grey-0 text-sm font-medium text-gray-700 hover:bg-gray-50 focus:outline-none"
2525
onClick={() => setIsOpen(!isOpen)}
2626
>
27-
{'value' in options[0] ? (
28-
options.find(opt => opt.value === selectedOption)?.label
27+
{options[0] && 'value' in options[0] ? (
28+
options.find(opt => opt?.value === selectedOption)?.label
2929
) : (
3030
<OptionComponent />
3131
)}

web-components/src/components/inputs/new/CustomSelect/CustomSelect.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const CustomSelect = ({
2020
const [isOpen, setIsOpen] = useState(false);
2121
const [selectedOption, setSelectedOption] = useState<string>(defaultOption);
2222
const [OptionComponent, setOptionComponent] = useState<ComponentType>(
23-
() => options[0].component?.element as ComponentType,
23+
() => options?.[0]?.component?.element as ComponentType,
2424
);
2525

2626
const handleSelect = (option: string) => {

web-marketplace/src/components/molecules/CreditsAmount/CreditsAmount.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ import {
1212
spendingCapAtom,
1313
} from 'pages/BuyCredits/BuyCredits.atoms';
1414
import { PAYMENT_OPTIONS } from 'pages/BuyCredits/BuyCredits.constants';
15-
import { getCreditsAvailableBannerText } from 'pages/BuyCredits/BuyCredits.utils';
15+
import {
16+
getCreditsAvailableBannerText,
17+
getOrderedSellOrders,
18+
} from 'pages/BuyCredits/BuyCredits.utils';
1619

1720
import { findDisplayDenom } from '../DenomLabel/DenomLabel.utils';
1821
import {
@@ -42,8 +45,6 @@ export const CreditsAmount = ({
4245
cryptoCurrencies,
4346
allowedDenoms,
4447
creditTypePrecision,
45-
card,
46-
orderedSellOrders,
4748
}: CreditsAmountProps) => {
4849
const { _ } = useLingui();
4950

@@ -54,6 +55,15 @@ export const CreditsAmount = ({
5455
const [spendingCap, setSpendingCap] = useAtom(spendingCapAtom);
5556
const paymentOption = useAtomValue(paymentOptionAtom);
5657

58+
const card = useMemo(
59+
() => paymentOption === PAYMENT_OPTIONS.CARD,
60+
[paymentOption],
61+
);
62+
const orderedSellOrders = useMemo(
63+
() => getOrderedSellOrders(card, cardSellOrders, filteredCryptoSellOrders),
64+
[card, cardSellOrders, filteredCryptoSellOrders],
65+
);
66+
5767
const displayDenom = useMemo(
5868
() =>
5969
findDisplayDenom({

web-marketplace/src/components/molecules/CreditsAmount/CreditsAmount.types.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export type Currency = {
1414
export interface CreditsAmountProps {
1515
creditsAvailable: number;
1616
setCreditsAvailable: UseStateSetter<number>;
17-
filteredCryptoSellOrders: Array<UISellOrderInfo> | undefined;
17+
filteredCryptoSellOrders: Array<UISellOrderInfo>;
1818
cardSellOrders: Array<CardSellOrder>;
1919
cryptoCurrencies: Currency[];
2020
allowedDenoms?: AllowedDenoms;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const KEPLR_LOGIN_REQUIRED = 'keplr-login-required';
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { Box } from '@mui/material';
2+
3+
import ContainedButton from 'web-components/src/components/buttons/ContainedButton';
4+
import OutlinedButton from 'web-components/src/components/buttons/OutlinedButton';
5+
import Card from 'web-components/src/components/cards/Card';
6+
import SellOrderNotFoundIcon from 'web-components/src/components/icons/SellOrderNotFoundIcon';
7+
import Modal from 'web-components/src/components/modal';
8+
import { Title } from 'web-components/src/components/typography';
9+
10+
import { UseStateSetter } from 'types/react/use-state';
11+
12+
import {
13+
BuyWarningModalContent,
14+
BuyWarningModalStateType,
15+
} from './BuyWarningModal.types';
16+
17+
interface BuyWarningModalProps extends BuyWarningModalContent {
18+
warningModalState: BuyWarningModalStateType;
19+
onClose: UseStateSetter<BuyWarningModalStateType>;
20+
handleClick: (action: string | null) => void;
21+
}
22+
23+
export const BuyWarningModal = ({
24+
modalContent,
25+
warningModalState,
26+
onClose,
27+
handleClick,
28+
}: BuyWarningModalProps) => {
29+
const { title, content, buttons } = modalContent;
30+
return (
31+
<Modal
32+
open={warningModalState.openModal}
33+
onClose={() => onClose({ ...warningModalState, openModal: false })}
34+
className="w-[560px] !py-40 !px-30"
35+
>
36+
<Box className="flex flex-col items-center">
37+
<SellOrderNotFoundIcon className="w-[100px] h-[100px]" />
38+
<Title variant="h4" className="text-center mt-20 px-30">
39+
{title}
40+
</Title>
41+
<Card className="text-left w-full py-40 px-30 my-40">{content}</Card>
42+
{buttons?.map((button, index) => {
43+
return button.type === 'outlined' ? (
44+
<OutlinedButton
45+
key={index}
46+
onClick={() => handleClick(button.action)}
47+
className={`h-[49px] ${
48+
buttons.find(button => button.type === 'contained')
49+
? 'w-[90%]'
50+
: ''
51+
}`}
52+
>
53+
{button.text}
54+
</OutlinedButton>
55+
) : (
56+
<ContainedButton
57+
size="small"
58+
onClick={() => handleClick(button.action)}
59+
key={index}
60+
className={`text-lg w-[90%] h-[49px] ${
61+
buttons.length > 1 ? 'mb-20' : ''
62+
}`}
63+
>
64+
{button.text}
65+
</ContainedButton>
66+
);
67+
})}
68+
</Box>
69+
</Modal>
70+
);
71+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export type BuyWarningModalStateType = {
2+
openModal: boolean;
3+
creditsAvailable: number;
4+
};
5+
type BuyWarningModalButtonType = 'outlined' | 'contained';
6+
7+
interface BuyWarningModalButton {
8+
text: string;
9+
action: string | null;
10+
type: BuyWarningModalButtonType;
11+
}
12+
13+
export interface BuyWarningModalContent {
14+
modalContent: {
15+
title: string;
16+
content: React.ReactNode;
17+
buttons: BuyWarningModalButton[];
18+
};
19+
}

web-marketplace/src/components/organisms/ChooseCreditsForm/ChooseCreditsForm.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,9 @@ export const ChooseCreditsForm = React.memo(
255255
PAYMENT_OPTIONS.CARD,
256256
);
257257
}
258+
if (!cardSellOrders.length && paymentOption === PAYMENT_OPTIONS.CARD) {
259+
handlePaymentOptions(PAYMENT_OPTIONS.CRYPTO);
260+
}
258261
}, [cardSellOrders.length, initialPaymentOption]); // just run this once
259262

260263
useEffect(() => {

web-marketplace/src/components/organisms/ConnectWalletFlow/ConnectWalletFlow.SelectAccountModal.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export const SelectAccountModal = ({
5555
<div className="pb-40">
5656
{accounts.map(account => (
5757
<div
58+
key={account.addr}
5859
className={`flex border-solid border border-grey-300 p-20 mb-10 rounded-[10px] cursor-pointer ${
5960
account.id === selectedAccountId ? 'bg-grey-200' : 'bg-grey-0'
6061
}`}

0 commit comments

Comments
 (0)