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

Fix SEP-6 flow #363

Merged
merged 1 commit into from
Sep 5, 2024
Merged
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
33 changes: 16 additions & 17 deletions packages/demo-wallet-client/src/components/Sep6Deposit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -297,23 +297,21 @@ export const Sep6Deposit = () => {
))}
</div>

{a.country_codes?.length && a.country_codes.length > 1 ? (
<div className="Sep6Selection">
<div className="Sep6Selection__label">Country code</div>
{a.country_codes?.map((c) => (
<RadioButton
key={c}
name="deposit-asset-country-code"
id={c}
label={c}
onChange={() => {
setSelectedDepositAssetCountryCode(c);
}}
checked={c === selectedDepositAssetCountryCode}
/>
))}
</div>
) : null}
<div className="Sep6Selection">
<div className="Sep6Selection__label">Country code</div>
{a.country_codes?.map((c) => (
<RadioButton
key={c}
name="deposit-asset-country-code"
id={c}
label={c}
onChange={() => {
setSelectedDepositAssetCountryCode(c);
}}
checked={c === selectedDepositAssetCountryCode}
/>
))}
</div>
</div>
))}
</div>
Expand Down Expand Up @@ -458,6 +456,7 @@ export const Sep6Deposit = () => {
) {
return (
<Sep6QuoteModal
type="deposit"
quote={sep6Deposit.data.quote}
onClose={handleClose}
onSubmit={handleSubmitWithQuote}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import { CSS_MODAL_PARENT_ID } from "demo-wallet-shared/build/constants/settings
import { AnchorQuote } from "types/types";

type Sep6QuoteModalProps = {
type: "deposit" | "withdrawal";
quote: AnchorQuote;
onClose: () => void;
onSubmit: (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
};

export const Sep6QuoteModal = ({
type,
quote,
onClose,
onSubmit,
Expand Down Expand Up @@ -66,7 +68,9 @@ export const Sep6QuoteModal = ({

return (
<Modal visible onClose={onClose} parentId={CSS_MODAL_PARENT_ID}>
<Modal.Heading>SEP-6 Deposit Quote</Modal.Heading>
<Modal.Heading>{`SEP-6 ${
type === "deposit" ? "Deposit" : "Withdrawal"
} Quote`}</Modal.Heading>
<Modal.Body>
<p>
These prices are indicative. The actual price will be calculated at
Expand Down
33 changes: 16 additions & 17 deletions packages/demo-wallet-client/src/components/Sep6Withdraw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -316,23 +316,21 @@ export const Sep6Withdraw = () => {
))}
</div>

{a.country_codes?.length && a.country_codes.length > 1 ? (
<div className="Sep6Selection">
<div className="Sep6Selection__label">Country code</div>
{a.country_codes?.map((c) => (
<RadioButton
key={c}
name="withdraw-asset-country-code"
id={c}
label={c}
onChange={() => {
setSelectedWithdrawAssetCountryCode(c);
}}
checked={c === selectedWithdrawAssetCountryCode}
/>
))}
</div>
) : null}
<div className="Sep6Selection">
<div className="Sep6Selection__label">Country code</div>
{a.country_codes?.map((c) => (
<RadioButton
key={c}
name="withdraw-asset-country-code"
id={c}
label={c}
onChange={() => {
setSelectedWithdrawAssetCountryCode(c);
}}
checked={c === selectedWithdrawAssetCountryCode}
/>
))}
</div>
</div>
))}
</div>
Expand Down Expand Up @@ -502,6 +500,7 @@ export const Sep6Withdraw = () => {
) {
return (
<Sep6QuoteModal
type="withdrawal"
quote={sep6Withdraw.data.quote}
onClose={handleClose}
onSubmit={handleSubmitWithQuote}
Expand Down
11 changes: 10 additions & 1 deletion packages/demo-wallet-client/src/ducks/sep6Deposit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export const initiateDepositAction = createAsyncThunk<
});

depositAssets = quotesResult.assets.filter(
(a) => a.asset !== buyAsset && a.buy_delivery_methods,
(a) => a.asset !== buyAsset && a.sell_delivery_methods,
);

log.instruction({
Expand All @@ -131,6 +131,15 @@ export const initiateDepositAction = createAsyncThunk<
});
}

const actionType =
supportsQuotes && depositAssets && depositAssets?.length > 0
? AnchorActionType.DEPOSIT_EXCHANGE
: AnchorActionType.DEPOSIT;

log.instruction({
title: `Selected ${actionType} path`,
});

// Get either deposit or deposit-exchange asset data
const assetInfoData =
infoData[
Expand Down
20 changes: 12 additions & 8 deletions packages/demo-wallet-client/src/ducks/sep6Withdraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export const initiateWithdrawAction = createAsyncThunk<
});

withdrawAssets = quotesResult.assets.filter(
(a) => a.asset !== sellAsset && a.sell_delivery_methods,
(a) => a.asset !== sellAsset && a.buy_delivery_methods,
);

log.instruction({
Expand All @@ -131,13 +131,17 @@ export const initiateWithdrawAction = createAsyncThunk<
});
}

// Get either deposit or deposit-exchange asset data
const assetInfoData =
infoData[
supportsQuotes && withdrawAssets && withdrawAssets?.length > 0
? AnchorActionType.WITHDRAW_EXCHANGE
: AnchorActionType.WITHDRAWAL
]?.[assetCode];
const actionType =
supportsQuotes && withdrawAssets && withdrawAssets?.length > 0
? AnchorActionType.WITHDRAW_EXCHANGE
: AnchorActionType.WITHDRAWAL;

log.instruction({
title: `Selected ${actionType} path`,
});

// Get either withdarw or withdraw-exchange asset data
const assetInfoData = infoData[actionType]?.[assetCode];

// This is unlikely
if (!assetInfoData) {
Expand Down