Skip to content

Commit

Permalink
update swap modal
Browse files Browse the repository at this point in the history
  • Loading branch information
richardliang committed Apr 11, 2024
1 parent 78abde4 commit 1cd748e
Show file tree
Hide file tree
Showing 23 changed files with 931 additions and 141 deletions.
208 changes: 208 additions & 0 deletions client/src/components/Deposit/CurrencySelector.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
import React, { useReducer, useRef } from "react";
import styled from 'styled-components';
import { X, ChevronDown } from 'react-feather';
import Link from '@mui/material/Link';

import { ThemedText } from '@theme/text';
import { colors } from '@theme/colors';
import { Overlay } from '@components/modals/Overlay';
import { CurrencyRow } from '@components/modals/CurrencyRow';
import { paymentPlatformInfo, PaymentPlatformType } from '@helpers/types';
import { useOnClickOutside } from '@hooks/useOnClickOutside';
import { ZKP2P_SURVEY_FORM_LINK } from "../../helpers/docUrls";
import usePlatformSettings from "@hooks/usePlatformSettings";


export const CurrencySelector: React.FC = () => {
const [isOpen, toggleOpen] = useReducer((s) => !s, false)

const ref = useRef<HTMLDivElement>(null)
useOnClickOutside(ref, isOpen ? toggleOpen : undefined)

/*
* Contexts
*/

const { paymentPlatform, currencyIndex, setCurrencyIndex } = usePlatformSettings();

/*
* Handlers
*/

const handleOverlayClick = () => {
toggleOpen();
};

const handleSelectCurrency = (currencyIndex: number) => {
if (setCurrencyIndex) {
setCurrencyIndex(currencyIndex);

toggleOpen();
}
};

/*
* Component
*/

return (
<Wrapper ref={ref}>
<CurrencyAndChevronContainer onClick={toggleOpen}>
<CurrencySvg src={paymentPlatformInfo[paymentPlatform as PaymentPlatformType].flagSvgs[currencyIndex ?? 0]} />
<CurrencyLabel>
{paymentPlatformInfo[paymentPlatform as PaymentPlatformType].platformCurrencies[currencyIndex ?? 0]}
</CurrencyLabel>
<StyledChevronDown/>
</CurrencyAndChevronContainer>

{isOpen && (
<ModalAndOverlayContainer>
<Overlay onClick={handleOverlayClick}/>

<ModalContainer>
<TableHeader>
<ThemedText.SubHeader style={{ textAlign: 'left' }}>
Select a currency
</ThemedText.SubHeader>

<button
onClick={handleOverlayClick}
style={{ background: 'none', border: 'none', cursor: 'pointer' }}
>
<StyledX/>
</button>
</TableHeader>

<HorizontalDivider/>

<Table>
{ paymentPlatformInfo[paymentPlatform as PaymentPlatformType].platformCurrencies.map((currency, currIndex) => (
<CurrencyRow
key={currIndex}
platformCurrency={currency}
flagSvg={paymentPlatformInfo[paymentPlatform as PaymentPlatformType].flagSvgs[currIndex]}
isSelected={currencyIndex === currIndex}
onRowClick={() => handleSelectCurrency(currIndex)}
/>
))}
</Table>

<HorizontalDivider/>

<TableFooter>
Let us know which currencies you are interested in seeing ZKP2P add support
for. <Link href={ ZKP2P_SURVEY_FORM_LINK } target="_blank">
Give feedback ↗
</Link>
</TableFooter>
</ModalContainer>
</ModalAndOverlayContainer>
)}
</Wrapper>
);
};

const Wrapper = styled.div`
display: flex;
justify-content: center;
align-items: center;
`;

const CurrencyAndChevronContainer = styled.div`
display: flex;
flex-direction: row;
align-items: center;
border-radius: 24px;
background: ${colors.selectorColor};
border: 1px solid rgba(255, 255, 255, 0.2);
padding: 4px 8px 4px 4px;
gap: 6px;
cursor: pointer;
&:hover {
background-color: ${colors.selectorHover};
border: 1px solid ${colors.selectorHoverBorder};
}
`;

const CurrencyLabel = styled.div`
color: #FFF;
font-weight: 700;
letter-spacing: 0.02em;
padding: 1px 5px 0px 5px;
`;

const CurrencySvg = styled.img`
border-radius: 18px;
width: 24px;
height: 24px;
`;

const StyledChevronDown = styled(ChevronDown)`
width: 20px;
height: 20px;
color: #FFF;
`;

const ModalAndOverlayContainer = styled.div`
width: 100vw;
height: 100vh;
display: flex;
justify-content: center;
position: fixed;
align-items: flex-start;
top: 0;
left: 0;
z-index: 10;
`;

const ModalContainer = styled.div`
width: 400px;
display: flex;
flex-direction: column;
border-radius: 16px;
border: 1px solid rgba(255, 255, 255, 0.2);
background-color: ${colors.container};
color: #FFF;
align-items: center;
z-index: 20;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
`;

const TableHeader = styled.div`
box-sizing: border-box;
width: 100%;
display: flex;
justify-content: space-between;
align-items: center;
padding: 20px 16px 16px 20px;
`;

const HorizontalDivider = styled.div`
width: 100%;
border-top: 1px solid ${colors.defaultBorderColor};
`;

const StyledX = styled(X)`
color: #FFF;
`;

const Table = styled.div`
width: 100%;
color: #616161;
height: 284px;
overflow-y: auto;
scrollbar-width: thin;
`;

const TableFooter = styled.div`
padding: 20px;
font-size: 14px;
text-align: left;
line-height: 1.5;
`;
4 changes: 3 additions & 1 deletion client/src/components/Deposit/DepositRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface PositionRowProps {
outstandingIntentAmount: string;
intentCount: string;
conversionRate: string;
conversionCurrency: string;
rowIndex: number;
isCancelDepositLoading: boolean;
handleWithdrawClick: () => void;
Expand All @@ -22,6 +23,7 @@ export const PositionRow: React.FC<PositionRowProps> = ({
outstandingIntentAmount,
intentCount,
conversionRate,
conversionCurrency,
rowIndex,
isCancelDepositLoading,
handleWithdrawClick
Expand Down Expand Up @@ -50,7 +52,7 @@ export const PositionRow: React.FC<PositionRowProps> = ({

<PercentageLabel>
<Label>Conversion Rate:</Label>
<Value>{conversionRate}</Value>
<Value>{conversionRate} {conversionCurrency}</Value>
</PercentageLabel>

<SummaryLabel>
Expand Down
40 changes: 27 additions & 13 deletions client/src/components/Deposit/DepositTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface DepositPrime {
outstandingIntentAmount: string;
intentCount: string;
conversionRate: string;
conversionCurrency: string;
}

interface PositionTableProps {
Expand Down Expand Up @@ -66,7 +67,7 @@ export const PositionTable: React.FC<PositionTableProps> = ({
wiseRampAbi
} = useSmartContracts();
const { refetchUsdcBalance } = useBalances();
const { PaymentPlatform, paymentPlatform, currencyIndex } = usePlatformSettings();
const { PaymentPlatform, paymentPlatform } = usePlatformSettings();

const {
isRegistered: isVenmoRegistered
Expand Down Expand Up @@ -213,23 +214,33 @@ export const PositionTable: React.FC<PositionTableProps> = ({

useEffect(() => {
let depositsToDisplay: DepositWithAvailableLiquidity[] | null = [];
let conversionCurrenciesToDisplay: string[] = [];
if (paymentPlatform) {
switch (paymentPlatform) {
case PaymentPlatform.VENMO:
depositsToDisplay = venmoDeposits;
depositsToDisplay = venmoDeposits ?? [];
conversionCurrenciesToDisplay = depositsToDisplay.map(() => 'USD')
break;

case PaymentPlatform.HDFC:
depositsToDisplay = hdfcDeposits;
depositsToDisplay = hdfcDeposits ?? [];
conversionCurrenciesToDisplay = depositsToDisplay.map(() => 'INR')
break;

case PaymentPlatform.GARANTI:
depositsToDisplay = garantiDeposits;
depositsToDisplay = garantiDeposits ?? [];
conversionCurrenciesToDisplay = depositsToDisplay.map(() => 'TRY')
break;

case PaymentPlatform.WISE:
const paymentPlatformCurrency = paymentPlatformInfo[PaymentPlatform.WISE].platformCurrencies[currencyIndex ?? 0];
depositsToDisplay = wiseDeposits?.filter(deposit => keccak256(paymentPlatformCurrency) === deposit.deposit.receiveCurrencyId) || null
depositsToDisplay = wiseDeposits ?? [];

conversionCurrenciesToDisplay = depositsToDisplay.map(depositToDisplay => (
paymentPlatformInfo[PaymentPlatform.WISE].platformCurrencies.find(
currency => keccak256(currency) === depositToDisplay.deposit.receiveCurrencyId
) ?? 'EUR'
))

break;

default:
Expand All @@ -241,7 +252,7 @@ export const PositionTable: React.FC<PositionTableProps> = ({
setPositionsRowData([]);
} else {
var sanitizedPositions: DepositPrime[] = [];
sanitizedPositions = depositsToDisplay.map((depositWithLiquidity: DepositWithAvailableLiquidity) => {
sanitizedPositions = depositsToDisplay.map((depositWithLiquidity: DepositWithAvailableLiquidity, index: number) => {
const deposit = depositWithLiquidity.deposit

const depositor = deposit.depositor;
Expand All @@ -250,22 +261,24 @@ export const PositionTable: React.FC<PositionTableProps> = ({
const intentCount = deposit.intentHashes.length.toString();
const outstandingIntentAmount = toUsdcString(deposit.outstandingIntentAmount, true);
const conversionRate = conversionRateToMultiplierString(deposit.conversionRate);
const conversionCurrency = conversionCurrenciesToDisplay[index];

return {
depositor,
availableDepositAmount,
totalDepositAmount,
outstandingIntentAmount,
intentCount,
conversionRate
conversionRate,
conversionCurrency
};
});

setPositionsRowData(sanitizedPositions);
}

// eslint-disable-next-line react-hooks/exhaustive-deps
}, [venmoDeposits, hdfcDeposits, garantiDeposits, wiseDeposits, paymentPlatform, currencyIndex]);
}, [venmoDeposits, hdfcDeposits, garantiDeposits, wiseDeposits, paymentPlatform]);

useEffect(() => {
const executeWithdrawDeposit = async () => {
Expand Down Expand Up @@ -395,7 +408,7 @@ export const PositionTable: React.FC<PositionTableProps> = ({
) : !isRegistered ? (
<ErrorContainer>
<PlatformSelectorContainer>
<PlatformSelector onlyDisplayPlatform={false} />
<PlatformSelector/>
</PlatformSelectorContainer>

<ThemedText.DeprecatedBody textAlign="center">
Expand All @@ -413,7 +426,7 @@ export const PositionTable: React.FC<PositionTableProps> = ({
) : positionsRowData.length === 0 ? (
<ErrorContainer>
<PlatformSelectorContainer>
<PlatformSelector onlyDisplayPlatform={false} />
<PlatformSelector/>
</PlatformSelectorContainer>

<ThemedText.DeprecatedBody textAlign="center">
Expand All @@ -426,7 +439,7 @@ export const PositionTable: React.FC<PositionTableProps> = ({
) : (
<PositionsContainer>
<PlatformSelectorContainer>
<PlatformSelector onlyDisplayPlatform={false} />
<PlatformSelector/>
</PlatformSelectorContainer>

<PositionCountTitle>
Expand All @@ -435,7 +448,7 @@ export const PositionTable: React.FC<PositionTableProps> = ({
</ThemedText.LabelSmall>

<PlatformSelectorContainer>
<PlatformSelector onlyDisplayPlatform={false} />
<PlatformSelector/>
</PlatformSelectorContainer>
</PositionCountTitle>

Expand All @@ -448,6 +461,7 @@ export const PositionTable: React.FC<PositionTableProps> = ({
outstandingIntentAmount={positionRow.outstandingIntentAmount}
intentCount={positionRow.intentCount}
conversionRate={positionRow.conversionRate}
conversionCurrency={positionRow.conversionCurrency}
rowIndex={rowIndex}
isCancelDepositLoading={rowIndex === selectedRowIndexToWithdraw && (isSubmitWithdrawLoading || isSubmitWithdrawMining)}
handleWithdrawClick={() => {
Expand Down

0 comments on commit 1cd748e

Please sign in to comment.