Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat : APP-363 another user purchased credits modal #2500

Open
wants to merge 23 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a863bd2
fix: add missing key in a map()
r41ph Oct 9, 2024
4a22cdd
fix: pagination issue in getSellOrdersExtendedQuery
r41ph Oct 9, 2024
a24c740
feat: add BuyFiatModal to handle purchase issues
r41ph Oct 10, 2024
ea1b866
feat: update SELL_ORDERS after purchase attempt
r41ph Oct 17, 2024
8c62efa
refactor: optimize getting ordered sell orders
r41ph Oct 22, 2024
42b47e9
refactor: BuyFiatModal + web2 users message and check all sellOrders …
r41ph Oct 23, 2024
ad4e8bb
refactor :BuyFiatModal props
r41ph Oct 23, 2024
38f938d
fix: types error
r41ph Oct 23, 2024
516c092
chore: update .po files
r41ph Oct 24, 2024
4e0703f
fix: sellCanProceed check
r41ph Oct 24, 2024
09b2059
fix: revert activeStep change for testing
r41ph Oct 24, 2024
c35de84
refactor: rename BuyFiatModal to BuyWarningModal
r41ph Nov 6, 2024
f70c5ae
feat: handle no connected wallet address
r41ph Nov 6, 2024
6c3da90
fix: amend merge
r41ph Nov 6, 2024
954a448
refactor: remove unused getFiatModalContent import
r41ph Dec 3, 2024
8b430db
fix: BuyWarningModal for visiting users and form state when no card s…
r41ph Dec 3, 2024
8bbc876
fix: avoid redirection when BuyWarningModal open
r41ph Dec 5, 2024
2d2b01f
chore: extract .po files
r41ph Dec 10, 2024
7bb097c
chore: update translation
r41ph Dec 10, 2024
91f967f
fix: filter sell orders by project
r41ph Dec 12, 2024
953f527
fix: remove user constrain for USD case warning modal
r41ph Dec 12, 2024
014992a
refactor: optimize getSellOrdersCredits
r41ph Jan 8, 2025
11671a7
fix: handle web3 accounts connected in BuyWarningModal
r41ph Jan 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function Placeholder({
isOpen,
options,
selectedOption,
OptionComponent,
OptionComponent = () => <></>,
ariaLabel,
}: {
setIsOpen: (isOpen: boolean) => void;
Expand All @@ -24,8 +24,8 @@ export function Placeholder({
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"
onClick={() => setIsOpen(!isOpen)}
>
{'value' in options[0] ? (
options.find(opt => opt.value === selectedOption)?.label
{options[0] && 'value' in options[0] ? (
options.find(opt => opt?.value === selectedOption)?.label
) : (
<OptionComponent />
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const CustomSelect = ({
const [isOpen, setIsOpen] = useState(false);
const [selectedOption, setSelectedOption] = useState<string>(defaultOption);
const [OptionComponent, setOptionComponent] = useState<ComponentType>(
() => options[0].component?.element as ComponentType,
() => options?.[0]?.component?.element as ComponentType,
);

const handleSelect = (option: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import {
spendingCapAtom,
} from 'pages/BuyCredits/BuyCredits.atoms';
import { PAYMENT_OPTIONS } from 'pages/BuyCredits/BuyCredits.constants';
import { getCreditsAvailableBannerText } from 'pages/BuyCredits/BuyCredits.utils';
import {
getCreditsAvailableBannerText,
getOrderedSellOrders,
} from 'pages/BuyCredits/BuyCredits.utils';

import { findDisplayDenom } from '../DenomLabel/DenomLabel.utils';
import {
Expand Down Expand Up @@ -42,8 +45,6 @@ export const CreditsAmount = ({
cryptoCurrencies,
allowedDenoms,
creditTypePrecision,
card,
orderedSellOrders,
}: CreditsAmountProps) => {
const { _ } = useLingui();

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

const card = useMemo(
() => paymentOption === PAYMENT_OPTIONS.CARD,
[paymentOption],
);
const orderedSellOrders = useMemo(
() => getOrderedSellOrders(card, cardSellOrders, filteredCryptoSellOrders),
[card, cardSellOrders, filteredCryptoSellOrders],
);

useEffect(() => {
// Set initial credits amount to min(1, creditsAvailable)
if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export type Currency = {
export interface CreditsAmountProps {
creditsAvailable: number;
setCreditsAvailable: UseStateSetter<number>;
filteredCryptoSellOrders: Array<UISellOrderInfo> | undefined;
filteredCryptoSellOrders: Array<UISellOrderInfo>;
cardSellOrders: Array<CardSellOrder>;
cryptoCurrencies: Currency[];
allowedDenoms?: AllowedDenoms;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const KEPLR_LOGIN_REQUIRED = 'keplr-login-required';
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { Box } from '@mui/material';

import ContainedButton from 'web-components/src/components/buttons/ContainedButton';
import OutlinedButton from 'web-components/src/components/buttons/OutlinedButton';
import Card from 'web-components/src/components/cards/Card';
import SellOrderNotFoundIcon from 'web-components/src/components/icons/SellOrderNotFoundIcon';
import Modal from 'web-components/src/components/modal';
import { Title } from 'web-components/src/components/typography';

import { UseStateSetter } from 'types/react/use-state';

import {
BuyWarningModalContent,
BuyWarningModalStateType,
} from './BuyWarningModal.types';

interface BuyWarningModalProps extends BuyWarningModalContent {
warningModalState: BuyWarningModalStateType;
onClose: UseStateSetter<BuyWarningModalStateType>;
handleClick: (action: string | null) => void;
}

export const BuyWarningModal = ({
modalContent,
warningModalState,
onClose,
handleClick,
}: BuyWarningModalProps) => {
const { title, content, buttons } = modalContent;
return (
<Modal
open={warningModalState.openModal}
onClose={() => onClose({ ...warningModalState, openModal: false })}
className="w-[560px] !py-40 !px-30"
>
<Box className="flex flex-col items-center">
<SellOrderNotFoundIcon className="w-[100px] h-[100px]" />
<Title variant="h4" className="text-center mt-20 px-30">
{title}
</Title>
<Card className="text-left w-full py-40 px-30 my-40">{content}</Card>
{buttons?.map((button, index) => {
return button.type === 'outlined' ? (
<OutlinedButton
key={index}
onClick={() => handleClick(button.action)}
className={`h-[49px] ${
buttons.find(button => button.type === 'contained')
? 'w-[90%]'
: ''
}`}
>
{button.text}
</OutlinedButton>
) : (
<ContainedButton
size="small"
onClick={() => handleClick(button.action)}
key={index}
className={`text-lg w-[90%] h-[49px] ${
buttons.length > 1 ? 'mb-20' : ''
}`}
>
{button.text}
</ContainedButton>
);
})}
</Box>
</Modal>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export type BuyWarningModalStateType = {
openModal: boolean;
creditsAvailable: number;
};
type BuyWarningModalButtonType = 'outlined' | 'contained';

interface BuyWarningModalButton {
text: string;
action: string | null;
type: BuyWarningModalButtonType;
}

export interface BuyWarningModalContent {
modalContent: {
title: string;
content: React.ReactNode;
buttons: BuyWarningModalButton[];
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ export const ChooseCreditsForm = React.memo(
PAYMENT_OPTIONS.CARD,
);
}
if (!cardSellOrders.length && paymentOption === PAYMENT_OPTIONS.CARD) {
handlePaymentOptions(PAYMENT_OPTIONS.CRYPTO);
}
}, [cardSellOrders.length, initialPaymentOption]); // just run this once

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const SelectAccountModal = ({
<div className="pb-40">
{accounts.map(account => (
<div
key={account.addr}
className={`flex border-solid border border-grey-300 p-20 mb-10 rounded-[10px] cursor-pointer ${
account.id === selectedAccountId ? 'bg-grey-200' : 'bg-grey-0'
}`}
Expand Down
Loading
Loading