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

Merged
merged 26 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
7538912
fix: add missing key in a map()
r41ph Oct 9, 2024
8bacc8b
fix: pagination issue in getSellOrdersExtendedQuery
r41ph Oct 9, 2024
7523332
feat: add BuyFiatModal to handle purchase issues
r41ph Oct 10, 2024
e4e6adf
feat: update SELL_ORDERS after purchase attempt
r41ph Oct 17, 2024
93a76bc
refactor: optimize getting ordered sell orders
r41ph Oct 22, 2024
ad29766
refactor: BuyFiatModal + web2 users message and check all sellOrders …
r41ph Oct 23, 2024
29597bd
refactor :BuyFiatModal props
r41ph Oct 23, 2024
806a9ab
fix: types error
r41ph Oct 23, 2024
9a0a4b4
chore: update .po files
r41ph Oct 24, 2024
9acd424
fix: sellCanProceed check
r41ph Oct 24, 2024
dcbf24f
fix: revert activeStep change for testing
r41ph Oct 24, 2024
5c8e364
refactor: rename BuyFiatModal to BuyWarningModal
r41ph Nov 6, 2024
b14add4
feat: handle no connected wallet address
r41ph Nov 6, 2024
ce122c2
fix: amend merge
r41ph Nov 6, 2024
247d124
refactor: remove unused getFiatModalContent import
r41ph Dec 3, 2024
9ce6bb9
fix: BuyWarningModal for visiting users and form state when no card s…
r41ph Dec 3, 2024
5726397
fix: avoid redirection when BuyWarningModal open
r41ph Dec 5, 2024
8b2206d
chore: extract .po files
r41ph Dec 10, 2024
57789f4
chore: update translation
r41ph Dec 10, 2024
900ee58
fix: filter sell orders by project
r41ph Dec 12, 2024
69ab1ed
fix: remove user constrain for USD case warning modal
r41ph Dec 12, 2024
c6caf77
refactor: optimize getSellOrdersCredits
r41ph Jan 8, 2025
265179b
fix: handle web3 accounts connected in BuyWarningModal
r41ph Jan 8, 2025
cce9295
fix: close modal on back to step 0 and sync localStorage activeStep
r41ph Jan 16, 2025
f8c5442
fix: deploy error by import findDisplayDenom
r41ph Jan 20, 2025
9382b0f
fix: remove duplicated msgid and msgstr
r41ph Jan 20, 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],
);

const displayDenom = useMemo(
() =>
findDisplayDenom({
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 @@ -255,6 +255,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