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: Add fiat & change wallet ability from the route drawer #2518

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion packages/checkout/widgets-lib/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@
"drawer": {
"options": {
"heading": "Pay from",
"moreOptionsDividerText": "More ways to Pay",
"moreOptionsDividerText": "Other ways to Pay",
"loadingText1": "Finding the best value",
"loadingText2": "across all chains",
"noRoutes": {
Expand All @@ -921,6 +921,7 @@
"caption": "Swap tokens on this network.",
"disabledCaption": "Currently not available."
},
"changeWallet": "Choose another wallet",
"debit": {
"heading": "Debit Card",
"caption": "",
Expand Down
3 changes: 2 additions & 1 deletion packages/checkout/widgets-lib/src/locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@
"drawer": {
"options": {
"heading": "支払い元",
"moreOptionsDividerText": "支払い方法の追加",
"moreOptionsDividerText": "その他の支払い方法",
"loadingText1": "最適な価値を検索中",
"loadingText2": "すべてのチェーンを横断",
"noRoutes": {
Expand All @@ -904,6 +904,7 @@
"caption": "このネットワークでトークンを交換します。",
"disabledCaption": "現在利用できません。"
},
"changeWallet": "別のウォレットを選択",
"debit": {
"heading": "デビットカード",
"caption": "",
Expand Down
1 change: 1 addition & 0 deletions packages/checkout/widgets-lib/src/locales/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,7 @@
"caption": "이 네트워크에서 토큰을 교환합니다.",
"disabledCaption": "현재 이용할 수 없습니다."
},
"changeWallet": "다른 지갑 선택",
"debit": {
"heading": "직불 카드",
"caption": "",
Expand Down
3 changes: 2 additions & 1 deletion packages/checkout/widgets-lib/src/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@
"drawer": {
"options": {
"heading": "支付来源",
"moreOptionsDividerText": "更多支付方式",
"moreOptionsDividerText": "其他支付方式",
"loadingText1": "寻找最佳价值",
"loadingText2": "跨所有链",
"noRoutes": {
Expand All @@ -901,6 +901,7 @@
"caption": "在此网络上交换代币。",
"disabledCaption": "当前不可用。"
},
"changeWallet": "选择另一个钱包",
"debit": {
"heading": "借记卡",
"caption": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ export function FiatOption<RC extends ReactElement | undefined = undefined>({
}`,
)}
</MenuItem.Caption>
{!disabled && <MenuItem.IntentIcon />}
</MenuItem>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface OptionsProps {
onCardClick: (type: FiatOptionType) => void;
onRouteClick: (route: RouteData, index: number) => void;
onDirectCryptoPayClick: (route: DirectCryptoPayData, index: number) => void;
onChangeWalletClick: () => void;
routes?: RouteData[];
size?: MenuItemSize;
showOnrampOption?: boolean;
Expand All @@ -42,6 +43,7 @@ export function RouteOptions({
onCardClick,
onRouteClick,
onDirectCryptoPayClick,
onChangeWalletClick,
size,
showOnrampOption,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down Expand Up @@ -137,11 +139,26 @@ export function RouteOptions({

{!routes?.length && !insufficientBalance && renderLoading()}

{showOnrampOption && (
{showOnrampOption && (routes?.length || insufficientBalance) && (
<>
<Divider size="xSmall" sx={{ my: 'base.spacing.x2' }}>
{t('views.PURCHASE.drawer.options.moreOptionsDividerText')}
</Divider>
<MenuItem
emphasized
onClick={onChangeWalletClick}
size="small"
>
<MenuItem.FramedIcon
icon="Wallet"
variant="bold"
emphasized={false}
/>
<MenuItem.Label>
{t('views.PURCHASE.drawer.options.changeWallet')}
</MenuItem.Label>
</MenuItem>

{defaultFiatOptions.map((type, idx) => (
<FiatOption
key={`fiat-option-${type}`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type OptionsDrawerProps = {
onRouteClick: (route: RouteData) => void;
onCardClick: (type: FiatOptionType) => void;
onDirectCryptoPayClick: (route: DirectCryptoPayData) => void;
onChangeWalletClick: () => void;
showOnrampOption?: boolean;
showDirectCryptoPayOption?: boolean;
showSwapOption?: boolean;
Expand All @@ -42,6 +43,7 @@ export function RouteOptionsDrawer({
onRouteClick,
onCardClick,
onDirectCryptoPayClick,
onChangeWalletClick,
showOnrampOption,
showDirectCryptoPayOption,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down Expand Up @@ -77,6 +79,11 @@ export function RouteOptionsDrawer({
onDirectCryptoPayClick(route);
};

const handleOnChangeWalletClick = () => {
onClose();
onChangeWalletClick();
};

useEffect(() => {
if (!visible) {
return;
Expand Down Expand Up @@ -132,7 +139,6 @@ export function RouteOptionsDrawer({
sx={{ c: 'inherit', fontSize: 'inherit' }}
/>
</MenuItem.Caption>

<MenuItem.StatefulButtCon icon="ChevronExpand" onClick={onClose} />
</MenuItem>
<RouteOptions
Expand All @@ -143,6 +149,7 @@ export function RouteOptionsDrawer({
onCardClick={onCardClick}
onRouteClick={handleOnRouteClick}
onDirectCryptoPayClick={handleOnDirectCryptoPayClick}
onChangeWalletClick={handleOnChangeWalletClick}
showOnrampOption={showOnrampOption}
showDirectCryptoPayOption={showDirectCryptoPayOption}
insufficientBalance={insufficientBalance}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -693,12 +693,14 @@ export function Purchase({
chains={chains}
showSwapOption={showSwapOption}
showBridgeOption={showBridgeOption}
showOnrampOption={shouldShowOnRampOption}
showDirectCryptoPayOption
visible={showOptionsDrawer}
onClose={() => setShowOptionsDrawer(false)}
onCardClick={handlePayWithCardClick}
onRouteClick={handleRouteClick}
onDirectCryptoPayClick={handleDirectCryptoPayClick}
onChangeWalletClick={() => setShowPayWithWalletDrawer(true)}
insufficientBalance={insufficientBalance}
directCryptoPayRoutes={directCryptoPayRoutes}
/>
Expand Down
Loading