Skip to content

Commit

Permalink
close modal on last conversoin
Browse files Browse the repository at this point in the history
  • Loading branch information
jonator committed Nov 6, 2024
1 parent 3c4fb02 commit bc46fb8
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions packages/web/modals/variants-conversion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,18 @@ export const AssetVariantsConversionModal = observer(() => {
}
);

// Use effect to close modal when no variants left
// This method, after testing, is more immediate than using tanstack's select
useEffect(() => {
if (
portfolioAssetsData &&
portfolioAssetsData.assetVariants.length === 0 &&
isOpen
) {
setIsOpen(false);
}
}, [portfolioAssetsData, isOpen, setIsOpen]);

// Log when opened
useEffect(() => {
if (isOpen) {
Expand Down Expand Up @@ -189,7 +201,6 @@ export const AssetVariantsConversionModal = observer(() => {
key={variant.amount.currency.coinMinimalDenom}
variant={variant}
showBottomBorder={index !== variants.length - 1}
onDoneConverting={() => setIsOpen(false)}
/>
)
)
Expand All @@ -203,8 +214,7 @@ export const AssetVariantsConversionModal = observer(() => {
const AssetVariantRow: React.FC<{
variant: AssetVariant;
showBottomBorder?: boolean;
onDoneConverting: () => void;
}> = observer(({ variant, showBottomBorder = true, onDoneConverting }) => {
}> = observer(({ variant, showBottomBorder = true }) => {
const { t } = useTranslation();
const { logEvent } = useAmplitudeAnalytics();
const { accountStore } = useStore();
Expand Down Expand Up @@ -356,7 +366,11 @@ const AssetVariantRow: React.FC<{
})}
disabled={conversionDisabled}
isLoading={isButtonLoading}
onClick={() => onConvert().catch(() => onDoneConverting)}
onClick={() =>
onConvert().catch((e) => {
console.error("Failed to convert", e);
})
}
>
{isButtonLoading ? "" : t("assetVariantsConversion.convert")}
</Button>
Expand Down

0 comments on commit bc46fb8

Please sign in to comment.