@rango-dev/widget-embedded 0.20.1-next.8 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/QueueManager.d.ts.map +1 -1
- package/dist/components/AppRouter.d.ts.map +1 -1
- package/dist/components/AppRoutes.d.ts.map +1 -1
- package/dist/components/BlockchainList/BlockchainList.styles.d.ts +169 -1
- package/dist/components/BlockchainList/BlockchainList.styles.d.ts.map +1 -1
- package/dist/components/BlockchainsSection/BlockchainsSection.styles.d.ts +4 -0
- package/dist/components/BlockchainsSection/BlockchainsSection.styles.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts +514 -1089
- package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/WalletList.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/WalletList.styles.d.ts +12 -0
- package/dist/components/ConfirmWalletsModal/WalletList.styles.d.ts.map +1 -1
- package/dist/components/CustomCollapsible/CustomCollapsible.d.ts +5 -0
- package/dist/components/CustomCollapsible/CustomCollapsible.d.ts.map +1 -0
- package/dist/components/CustomCollapsible/CustomCollapsible.styles.d.ts +654 -0
- package/dist/components/CustomCollapsible/CustomCollapsible.styles.d.ts.map +1 -0
- package/dist/components/CustomCollapsible/CustomCollapsible.types.d.ts +10 -0
- package/dist/components/CustomCollapsible/CustomCollapsible.types.d.ts.map +1 -0
- package/dist/components/HeaderButtons/HeaderButtons.styles.d.ts +20 -0
- package/dist/components/HeaderButtons/HeaderButtons.styles.d.ts.map +1 -1
- package/dist/components/HeaderButtons/HeaderButtons.types.d.ts +0 -1
- package/dist/components/HeaderButtons/HeaderButtons.types.d.ts.map +1 -1
- package/dist/components/HeaderButtons/HomeButtons.d.ts.map +1 -1
- package/dist/components/Layout/Layout.d.ts +2 -3
- package/dist/components/Layout/Layout.d.ts.map +1 -1
- package/dist/components/Layout/Layout.helpers.d.ts +2 -0
- package/dist/components/Layout/Layout.helpers.d.ts.map +1 -0
- package/dist/components/Layout/Layout.styles.d.ts +14 -4
- package/dist/components/Layout/Layout.styles.d.ts.map +1 -1
- package/dist/components/Layout/Layout.types.d.ts +6 -3
- package/dist/components/Layout/Layout.types.d.ts.map +1 -1
- package/dist/components/Layout/PageContainer.d.ts +166 -0
- package/dist/components/Layout/PageContainer.d.ts.map +1 -0
- package/dist/components/Layout/ScrollableArea.d.ts +164 -0
- package/dist/components/Layout/ScrollableArea.d.ts.map +1 -0
- package/dist/components/Layout/index.d.ts +2 -0
- package/dist/components/Layout/index.d.ts.map +1 -1
- package/dist/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.styles.d.ts +4 -0
- package/dist/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.styles.d.ts.map +1 -1
- package/dist/components/LoadingSwapDetails/LoadingSwapDetails.styles.d.ts +56 -0
- package/dist/components/LoadingSwapDetails/LoadingSwapDetails.styles.d.ts.map +1 -1
- package/dist/components/NoResult/NoResult.styles.d.ts +12 -0
- package/dist/components/NoResult/NoResult.styles.d.ts.map +1 -1
- package/dist/components/NotificationContent/NotificationContent.d.ts.map +1 -1
- package/dist/components/NotificationContent/NotificationContent.styles.d.ts +16 -0
- package/dist/components/NotificationContent/NotificationContent.styles.d.ts.map +1 -1
- package/dist/components/Quote/Quote.d.ts.map +1 -1
- package/dist/components/Quote/Quote.styles.d.ts +387 -3
- package/dist/components/Quote/Quote.styles.d.ts.map +1 -1
- package/dist/components/Quote/Quote.types.d.ts +19 -0
- package/dist/components/Quote/Quote.types.d.ts.map +1 -1
- package/dist/components/Quote/QuoteCostDetails.d.ts +4 -0
- package/dist/components/Quote/QuoteCostDetails.d.ts.map +1 -0
- package/dist/components/Quote/QuoteCostDetails.styles.d.ts +806 -0
- package/dist/components/Quote/QuoteCostDetails.styles.d.ts.map +1 -0
- package/dist/components/Quote/QuoteSummary.d.ts.map +1 -1
- package/dist/components/Quote/QuoteSummary.styles.d.ts +8 -0
- package/dist/components/Quote/QuoteSummary.styles.d.ts.map +1 -1
- package/dist/components/Quote/QuoteTrigger .d.ts +4 -0
- package/dist/components/Quote/QuoteTrigger .d.ts.map +1 -0
- package/dist/components/QuoteSkeleton/QuoteSkeleton.styles.d.ts +16 -0
- package/dist/components/QuoteSkeleton/QuoteSkeleton.styles.d.ts.map +1 -1
- package/dist/components/QuoteSkeleton/QuoteSummarySkeleton.styles.d.ts +40 -0
- package/dist/components/QuoteSkeleton/QuoteSummarySkeleton.styles.d.ts.map +1 -1
- package/dist/components/QuoteSkeleton/StepSkeleton.styles.d.ts +20 -0
- package/dist/components/QuoteSkeleton/StepSkeleton.styles.d.ts.map +1 -1
- package/dist/components/QuoteWarningsAndErrors/HighValueLossWarningModal.d.ts +1 -0
- package/dist/components/QuoteWarningsAndErrors/HighValueLossWarningModal.d.ts.map +1 -1
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.d.ts.map +1 -1
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.styles.d.ts +16 -0
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.styles.d.ts.map +1 -1
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.types.d.ts +1 -0
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.types.d.ts.map +1 -1
- package/dist/components/QuoteWarningsAndErrors/SlippageWariningModal.d.ts +1 -0
- package/dist/components/QuoteWarningsAndErrors/SlippageWariningModal.d.ts.map +1 -1
- package/dist/components/QuoteWarningsAndErrors/UnknownPriceWarningModal.d.ts +1 -0
- package/dist/components/QuoteWarningsAndErrors/UnknownPriceWarningModal.d.ts.map +1 -1
- package/dist/components/SearchInput/SearchInput.styles.d.ts +4 -0
- package/dist/components/SearchInput/SearchInput.styles.d.ts.map +1 -1
- package/dist/components/SettingsContainer/SettingsContainer.style.d.ts +11 -156
- package/dist/components/SettingsContainer/SettingsContainer.style.d.ts.map +1 -1
- package/dist/components/SettingsContainer/index.d.ts +1 -1
- package/dist/components/SettingsContainer/index.d.ts.map +1 -1
- package/dist/components/Slippage/Slippage.styles.d.ts +20 -0
- package/dist/components/Slippage/Slippage.styles.d.ts.map +1 -1
- package/dist/components/SwapDetails/SwapDetails.Placeholder.d.ts.map +1 -1
- package/dist/components/SwapDetails/SwapDetails.d.ts.map +1 -1
- package/dist/components/SwapDetails/SwapDetails.helpers.d.ts +1 -1
- package/dist/components/SwapDetails/SwapDetails.helpers.d.ts.map +1 -1
- package/dist/components/SwapDetails/SwapDetails.styles.d.ts +523 -1
- package/dist/components/SwapDetails/SwapDetails.styles.d.ts.map +1 -1
- package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.d.ts.map +1 -1
- package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.styles.d.ts +4 -0
- package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.styles.d.ts.map +1 -1
- package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.types.d.ts +2 -1
- package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.types.d.ts.map +1 -1
- package/dist/components/SwapDetailsModal/SwapDetailsModal.WalletState.d.ts.map +1 -1
- package/dist/components/SwapDetailsModal/SwapDetailsModal.d.ts.map +1 -1
- package/dist/components/SwapDetailsModal/SwapDetailsModal.styles.d.ts +4 -0
- package/dist/components/SwapDetailsModal/SwapDetailsModal.styles.d.ts.map +1 -1
- package/dist/components/SwapDetailsModal/SwapDetailsModal.types.d.ts +2 -0
- package/dist/components/SwapDetailsModal/SwapDetailsModal.types.d.ts.map +1 -1
- package/dist/components/SwapsGroup/SwapsGroup.d.ts.map +1 -1
- package/dist/components/SwapsGroup/SwapsGroup.styles.d.ts +20 -0
- package/dist/components/SwapsGroup/SwapsGroup.styles.d.ts.map +1 -1
- package/dist/components/TokenList/TokenList.styles.d.ts +68 -0
- package/dist/components/TokenList/TokenList.styles.d.ts.map +1 -1
- package/dist/components/WalletModal/WalletModalContent.styles.d.ts +16 -0
- package/dist/components/WalletModal/WalletModalContent.styles.d.ts.map +1 -1
- package/dist/components/WidgetEvents.d.ts.map +1 -1
- package/dist/components/common/ActivateTabAlert/ActivateTabAlert.d.ts +4 -0
- package/dist/components/common/ActivateTabAlert/ActivateTabAlert.d.ts.map +1 -0
- package/dist/components/common/ActivateTabAlert/ActivateTabAlert.types.d.ts +4 -0
- package/dist/components/common/ActivateTabAlert/ActivateTabAlert.types.d.ts.map +1 -0
- package/dist/components/common/ActivateTabAlert/index.d.ts +2 -0
- package/dist/components/common/ActivateTabAlert/index.d.ts.map +1 -0
- package/dist/components/common/ActivateTabModal/ActivateTabModal.d.ts +4 -0
- package/dist/components/common/ActivateTabModal/ActivateTabModal.d.ts.map +1 -0
- package/dist/components/common/ActivateTabModal/ActivateTabModal.types.d.ts +6 -0
- package/dist/components/common/ActivateTabModal/ActivateTabModal.types.d.ts.map +1 -0
- package/dist/components/common/ActivateTabModal/index.d.ts +2 -0
- package/dist/components/common/ActivateTabModal/index.d.ts.map +1 -0
- package/dist/constants/index.d.ts +1 -0
- package/dist/constants/index.d.ts.map +1 -1
- package/dist/constants/quote.d.ts +12 -0
- package/dist/constants/quote.d.ts.map +1 -0
- package/dist/constants/searchParams.d.ts +6 -6
- package/dist/constants/searchParams.d.ts.map +1 -1
- package/dist/containers/App/App.d.ts.map +1 -1
- package/dist/containers/App/App.styles.d.ts +4 -0
- package/dist/containers/App/App.styles.d.ts.map +1 -1
- package/dist/containers/QuoteInfo/QuoteInfo.d.ts +1 -1
- package/dist/containers/QuoteInfo/QuoteInfo.d.ts.map +1 -1
- package/dist/containers/QuoteInfo/QuoteInfo.styles.d.ts +10 -314
- package/dist/containers/QuoteInfo/QuoteInfo.styles.d.ts.map +1 -1
- package/dist/containers/QuoteInfo/QuoteInfo.types.d.ts +0 -7
- package/dist/containers/QuoteInfo/QuoteInfo.types.d.ts.map +1 -1
- package/dist/containers/Widget/Widget.d.ts.map +1 -1
- package/dist/containers/WidgetInfo/WidgetInfo.d.ts.map +1 -1
- package/dist/containers/WidgetInfo/WidgetInfo.types.d.ts +7 -0
- package/dist/containers/WidgetInfo/WidgetInfo.types.d.ts.map +1 -1
- package/dist/containers/WidgetProvider/WidgetProvider.d.ts.map +1 -1
- package/dist/hooks/useLanguage.d.ts +2 -1
- package/dist/hooks/useLanguage.d.ts.map +1 -1
- package/dist/hooks/useSwapInput.d.ts.map +1 -1
- package/dist/hooks/useSyncStoresWithConfig.d.ts.map +1 -1
- package/dist/hooks/useSyncUrlAndStore/index.d.ts +2 -0
- package/dist/hooks/useSyncUrlAndStore/index.d.ts.map +1 -0
- package/dist/hooks/useSyncUrlAndStore/useSyncUrlAndStore.d.ts +2 -0
- package/dist/hooks/useSyncUrlAndStore/useSyncUrlAndStore.d.ts.map +1 -0
- package/dist/hooks/useSyncUrlAndStore/useSyncUrlAndStore.helpers.d.ts +4 -0
- package/dist/hooks/useSyncUrlAndStore/useSyncUrlAndStore.helpers.d.ts.map +1 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +4 -4
- package/dist/libs/tabManager/index.d.ts +3 -0
- package/dist/libs/tabManager/index.d.ts.map +1 -0
- package/dist/libs/tabManager/tabManager.constants.d.ts +4 -0
- package/dist/libs/tabManager/tabManager.constants.d.ts.map +1 -0
- package/dist/libs/tabManager/tabManager.d.ts +63 -0
- package/dist/libs/tabManager/tabManager.d.ts.map +1 -0
- package/dist/libs/tabManager/tabManager.types.d.ts +29 -0
- package/dist/libs/tabManager/tabManager.types.d.ts.map +1 -0
- package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
- package/dist/pages/HistoryPage.d.ts.map +1 -1
- package/dist/pages/Home.d.ts.map +1 -1
- package/dist/pages/LanguagePage.d.ts.map +1 -1
- package/dist/pages/LiquiditySourcePage.d.ts.map +1 -1
- package/dist/pages/SelectSwapItemsPage.d.ts.map +1 -1
- package/dist/pages/SettingsPage.d.ts.map +1 -1
- package/dist/pages/SwapDetailsPage.d.ts.map +1 -1
- package/dist/pages/ThemePage.d.ts.map +1 -1
- package/dist/pages/WalletsPage.d.ts.map +1 -1
- package/dist/store/AppStore.d.ts +2 -2
- package/dist/store/app.d.ts +2 -2
- package/dist/store/slices/settings.d.ts +2 -2
- package/dist/store/slices/settings.d.ts.map +1 -1
- package/dist/store/ui.d.ts +12 -10
- package/dist/store/ui.d.ts.map +1 -1
- package/dist/types/notification.d.ts +1 -2
- package/dist/types/notification.d.ts.map +1 -1
- package/dist/utils/date.d.ts.map +1 -1
- package/dist/utils/quote.d.ts +5 -2
- package/dist/utils/quote.d.ts.map +1 -1
- package/dist/utils/swap.d.ts +5 -1
- package/dist/utils/swap.d.ts.map +1 -1
- package/dist/utils/ui.d.ts +2 -0
- package/dist/utils/ui.d.ts.map +1 -1
- package/package.json +7 -7
- package/src/QueueManager.tsx +4 -1
- package/src/components/AppRouter.tsx +1 -8
- package/src/components/AppRoutes.tsx +11 -0
- package/src/components/BlockchainList/BlockchainList.styles.ts +4 -3
- package/src/components/BlockchainList/BlockchainList.tsx +1 -1
- package/src/components/ConfirmWalletsModal/ConfirmWallets.styles.ts +27 -96
- package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +25 -40
- package/src/components/ConfirmWalletsModal/WalletList.tsx +3 -0
- package/src/components/CustomCollapsible/CustomCollapsible.styles.ts +75 -0
- package/src/components/CustomCollapsible/CustomCollapsible.tsx +55 -0
- package/src/components/CustomCollapsible/CustomCollapsible.types.ts +10 -0
- package/src/components/HeaderButtons/HeaderButtons.styles.ts +4 -1
- package/src/components/HeaderButtons/HeaderButtons.types.ts +0 -1
- package/src/components/HeaderButtons/HomeButtons.tsx +1 -2
- package/src/components/Layout/Layout.helpers.ts +16 -0
- package/src/components/Layout/Layout.styles.ts +17 -31
- package/src/components/Layout/Layout.tsx +60 -29
- package/src/components/Layout/Layout.types.ts +9 -8
- package/src/components/Layout/PageContainer.tsx +24 -0
- package/src/components/Layout/ScrollableArea.tsx +11 -0
- package/src/components/Layout/index.ts +2 -0
- package/src/components/NotificationContent/NotificationContent.tsx +10 -4
- package/src/components/Quote/Quote.styles.ts +44 -5
- package/src/components/Quote/Quote.tsx +10 -77
- package/src/components/Quote/Quote.types.ts +22 -0
- package/src/components/Quote/QuoteCostDetails.styles.ts +50 -0
- package/src/components/Quote/QuoteCostDetails.tsx +218 -0
- package/src/components/Quote/QuoteSummary.tsx +3 -2
- package/src/components/Quote/QuoteTrigger .tsx +215 -0
- package/src/components/QuoteWarningsAndErrors/HighValueLossWarningModal.tsx +3 -1
- package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.styles.ts +0 -1
- package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.tsx +3 -1
- package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.types.ts +1 -0
- package/src/components/QuoteWarningsAndErrors/SlippageWariningModal.tsx +3 -1
- package/src/components/QuoteWarningsAndErrors/UnknownPriceWarningModal.tsx +3 -1
- package/src/components/SettingsContainer/SettingsContainer.style.ts +0 -5
- package/src/components/SettingsContainer/index.ts +0 -1
- package/src/components/Slippage/Slippage.tsx +5 -5
- package/src/components/Slippage/SlippageTooltipContent.tsx +1 -1
- package/src/components/SwapDetails/SwapDetails.Placeholder.tsx +12 -13
- package/src/components/SwapDetails/SwapDetails.helpers.tsx +43 -3
- package/src/components/SwapDetails/SwapDetails.styles.ts +18 -6
- package/src/components/SwapDetails/SwapDetails.tsx +16 -5
- package/src/components/SwapDetailsAlerts/SwapDetailsAlerts.tsx +13 -7
- package/src/components/SwapDetailsAlerts/SwapDetailsAlerts.types.ts +2 -0
- package/src/components/SwapDetailsModal/SwapDetailsModal.WalletState.tsx +9 -1
- package/src/components/SwapDetailsModal/SwapDetailsModal.tsx +10 -2
- package/src/components/SwapDetailsModal/SwapDetailsModal.types.ts +2 -0
- package/src/components/SwapsGroup/SwapsGroup.tsx +18 -7
- package/src/components/TokenList/TokenList.styles.ts +2 -0
- package/src/components/TokenList/TokenList.tsx +1 -1
- package/src/components/WidgetEvents.tsx +2 -14
- package/src/components/common/ActivateTabAlert/ActivateTabAlert.tsx +26 -0
- package/src/components/common/ActivateTabAlert/ActivateTabAlert.types.ts +3 -0
- package/src/components/common/ActivateTabAlert/index.ts +1 -0
- package/src/components/common/ActivateTabModal/ActivateTabModal.tsx +31 -0
- package/src/components/common/ActivateTabModal/ActivateTabModal.types.ts +5 -0
- package/src/components/common/ActivateTabModal/index.ts +1 -0
- package/src/constants/index.ts +1 -0
- package/src/constants/quote.ts +23 -0
- package/src/constants/searchParams.ts +6 -6
- package/src/containers/App/App.styles.ts +2 -0
- package/src/containers/App/App.tsx +1 -4
- package/src/containers/QuoteInfo/QuoteInfo.styles.ts +0 -15
- package/src/containers/QuoteInfo/QuoteInfo.tsx +30 -77
- package/src/containers/QuoteInfo/QuoteInfo.types.ts +0 -7
- package/src/containers/Wallets/Wallets.tsx +3 -3
- package/src/containers/Widget/Widget.tsx +6 -1
- package/src/containers/WidgetInfo/WidgetInfo.tsx +13 -1
- package/src/containers/WidgetInfo/WidgetInfo.types.ts +7 -0
- package/src/containers/WidgetProvider/WidgetProvider.tsx +2 -1
- package/src/hooks/useLanguage.ts +6 -4
- package/src/hooks/useSwapInput.ts +6 -1
- package/src/hooks/useSyncStoresWithConfig.ts +3 -17
- package/src/hooks/useSyncUrlAndStore/index.ts +1 -0
- package/src/hooks/useSyncUrlAndStore/useSyncUrlAndStore.helpers.ts +35 -0
- package/src/hooks/useSyncUrlAndStore/useSyncUrlAndStore.ts +135 -0
- package/src/index.ts +2 -2
- package/src/libs/tabManager/index.ts +2 -0
- package/src/libs/tabManager/tabManager.constants.ts +3 -0
- package/src/libs/tabManager/tabManager.ts +222 -0
- package/src/libs/tabManager/tabManager.types.ts +28 -0
- package/src/pages/ConfirmSwapPage.tsx +55 -47
- package/src/pages/HistoryPage.tsx +5 -17
- package/src/pages/Home.tsx +47 -43
- package/src/pages/LanguagePage.tsx +3 -4
- package/src/pages/LiquiditySourcePage.tsx +8 -6
- package/src/pages/SelectBlockchainPage.tsx +41 -41
- package/src/pages/SelectSwapItemsPage.tsx +45 -39
- package/src/pages/SettingsPage.tsx +3 -4
- package/src/pages/SwapDetailsPage.tsx +21 -7
- package/src/pages/ThemePage.tsx +3 -4
- package/src/pages/WalletsPage.tsx +15 -13
- package/src/store/slices/settings.ts +3 -3
- package/src/store/ui.ts +39 -11
- package/src/types/notification.ts +0 -7
- package/src/utils/date.ts +5 -4
- package/src/utils/quote.ts +18 -28
- package/src/utils/swap.ts +35 -0
- package/src/utils/ui.ts +20 -0
- package/dist/components/UpdateUrl.d.ts +0 -2
- package/dist/components/UpdateUrl.d.ts.map +0 -1
- package/src/components/UpdateUrl.tsx +0 -158
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Events,
|
|
3
|
+
ID,
|
|
4
|
+
Message,
|
|
5
|
+
TabManagerInterface,
|
|
6
|
+
} from './tabManager.types';
|
|
7
|
+
|
|
8
|
+
import { CHANNEL_NAME, MAXIMUM_TAB_ID, TIMEOUT } from './tabManager.constants';
|
|
9
|
+
|
|
10
|
+
export class TabManager implements TabManagerInterface {
|
|
11
|
+
private tabId: ID;
|
|
12
|
+
private state: 'not-initiated' | 'not-claimed' | 'claimed' = 'not-initiated';
|
|
13
|
+
private lastTryClaim: number | undefined;
|
|
14
|
+
private events: Events = {};
|
|
15
|
+
private channel: BroadcastChannel;
|
|
16
|
+
|
|
17
|
+
constructor(events: Events) {
|
|
18
|
+
this.channel = new BroadcastChannel(CHANNEL_NAME);
|
|
19
|
+
this.tabId = Math.trunc(Math.random() * MAXIMUM_TAB_ID);
|
|
20
|
+
this.events = events;
|
|
21
|
+
this.initEvents();
|
|
22
|
+
void this.tryClaim();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* This is applicable when a user in an inactive tab seeks to activate that tab.
|
|
27
|
+
*/
|
|
28
|
+
forceClaim = () => {
|
|
29
|
+
if (!this.isClaimed()) {
|
|
30
|
+
const message: Message = { name: 'force-claim', candidateId: this.tabId };
|
|
31
|
+
this.channel.postMessage(message);
|
|
32
|
+
setTimeout(() => {
|
|
33
|
+
if (!this.isClaimed()) {
|
|
34
|
+
this.claim();
|
|
35
|
+
}
|
|
36
|
+
}, TIMEOUT);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
isClaimed = () => {
|
|
41
|
+
return this.state === 'claimed';
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* remove event listeners
|
|
46
|
+
*/
|
|
47
|
+
destroy = () => {
|
|
48
|
+
this.channel.removeEventListener('message', this.handleMessageEvent);
|
|
49
|
+
document.removeEventListener(
|
|
50
|
+
'visibilitychange',
|
|
51
|
+
this.handleVisibilityChange
|
|
52
|
+
);
|
|
53
|
+
document.removeEventListener('resume', this.handleResume);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Reacting to messages and window events to claim.
|
|
58
|
+
*/
|
|
59
|
+
private initEvents() {
|
|
60
|
+
this.channel.addEventListener('message', this.handleMessageEvent);
|
|
61
|
+
|
|
62
|
+
document.addEventListener('visibilitychange', this.handleVisibilityChange);
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The "resume" event is currently supported only in certain browsers.
|
|
66
|
+
* It is triggered when a previously frozen tab is unfrozen and resumes execution.
|
|
67
|
+
* To avoid having multiple active tabs,
|
|
68
|
+
* if the current tab is active after the "resume" event,
|
|
69
|
+
* we send a signal to other tabs to verify if any of them currently claim to be active.
|
|
70
|
+
* If this is the case, we deactivate the current tab.
|
|
71
|
+
* https://developer.chrome.com/docs/web-platform/page-lifecycle-api
|
|
72
|
+
*/
|
|
73
|
+
document.addEventListener('resume', this.handleResume);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Runs after a `ping` message and checks if current tab is claimed the tabs,
|
|
78
|
+
* if yes, it responds with `pong`, If not, it doesn't do anything.
|
|
79
|
+
*
|
|
80
|
+
* Note 1: If we receive a `ping` message,
|
|
81
|
+
* it means a tab is trying to claim tabs directly, usually it's the active tab.
|
|
82
|
+
*
|
|
83
|
+
* Note 2: If multiple tabs are opening at once, all of them are broadcasting `ping`
|
|
84
|
+
* and eventually all of them will `claim` the queue after the TIMEOUT.
|
|
85
|
+
* For avoiding this, we will accepts the oldest broadcasted ping. (`isPingSentBefore`)
|
|
86
|
+
*/
|
|
87
|
+
private claimedByCurrentTab(pingAt: number) {
|
|
88
|
+
const isPingSentBefore = this.lastTryClaim && this.lastTryClaim < pingAt;
|
|
89
|
+
|
|
90
|
+
if (this.isClaimed() || isPingSentBefore) {
|
|
91
|
+
const message: Message = {
|
|
92
|
+
name: 'pong',
|
|
93
|
+
};
|
|
94
|
+
this.channel.postMessage(message);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
private handleMessageEvent = (event: MessageEvent<Message>) => {
|
|
100
|
+
const name = event.data.name;
|
|
101
|
+
|
|
102
|
+
switch (name) {
|
|
103
|
+
case 'ping':
|
|
104
|
+
this.claimedByCurrentTab(event.data.pingAt);
|
|
105
|
+
break;
|
|
106
|
+
|
|
107
|
+
case 'pong':
|
|
108
|
+
this.alreadyClaimedByAnotherTab();
|
|
109
|
+
break;
|
|
110
|
+
|
|
111
|
+
case 'force-claim':
|
|
112
|
+
this.forceRelease(event.data.candidateId);
|
|
113
|
+
break;
|
|
114
|
+
|
|
115
|
+
case 'force-release':
|
|
116
|
+
if (this.tabId === event.data.candidateId) {
|
|
117
|
+
this.claim();
|
|
118
|
+
}
|
|
119
|
+
break;
|
|
120
|
+
|
|
121
|
+
default:
|
|
122
|
+
throw new Error(`${name} is not supported.`);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
private handleVisibilityChange = async () => {
|
|
127
|
+
if (document.visibilityState === 'visible') {
|
|
128
|
+
await this.tryClaim();
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
private handleResume = async () => {
|
|
133
|
+
if (this.isClaimed()) {
|
|
134
|
+
await this.tryClaim();
|
|
135
|
+
if (!this.isClaimed()) {
|
|
136
|
+
this.events.onRelease?.();
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
/**
|
|
141
|
+
* Runs after receiving `pong` message, which means one of tabs already claimed the tabs.
|
|
142
|
+
*/
|
|
143
|
+
private alreadyClaimedByAnotherTab() {
|
|
144
|
+
this.resetLastCheck();
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Try to send a `ping` message to know if the tabs `claimed` or not.
|
|
149
|
+
* On constructing instance, or whenever page is active we will try.
|
|
150
|
+
*/
|
|
151
|
+
private async tryClaim() {
|
|
152
|
+
/**
|
|
153
|
+
* Try to ask from possible other running tabs.
|
|
154
|
+
*/
|
|
155
|
+
this.setLastCheck();
|
|
156
|
+
return new Promise<void>((resolve) => {
|
|
157
|
+
setTimeout(() => {
|
|
158
|
+
this.check();
|
|
159
|
+
resolve();
|
|
160
|
+
}, TIMEOUT);
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* If `lastCheck` is exist, it means there is no other tabs which `claimed` the tabs.
|
|
166
|
+
* And we mark the current tab as `claimed`
|
|
167
|
+
*/
|
|
168
|
+
private check() {
|
|
169
|
+
if (this.state === 'not-initiated') {
|
|
170
|
+
this.events.onInit?.();
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
*it means we didn't get any response from other tabs, this tab can claim.
|
|
174
|
+
*/
|
|
175
|
+
if (this.lastTryClaim) {
|
|
176
|
+
this.claim();
|
|
177
|
+
this.resetLastCheck();
|
|
178
|
+
} else {
|
|
179
|
+
this.state = 'not-claimed';
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
private claim() {
|
|
184
|
+
this.state = 'claimed';
|
|
185
|
+
this.events.onClaim?.();
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Setting current time as `lastCheck` and broadcast a `ping` message event.
|
|
190
|
+
*/
|
|
191
|
+
private setLastCheck() {
|
|
192
|
+
this.lastTryClaim = Date.now();
|
|
193
|
+
const message: Message = {
|
|
194
|
+
name: 'ping',
|
|
195
|
+
pingAt: this.lastTryClaim,
|
|
196
|
+
};
|
|
197
|
+
this.channel.postMessage(message);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
private resetLastCheck() {
|
|
201
|
+
this.lastTryClaim = undefined;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Upon receipt of a "force-claim" message,
|
|
206
|
+
* the presently active tab is expected to deactivate itself and initiate any attached callback associated with this event.
|
|
207
|
+
*/
|
|
208
|
+
private forceRelease(nextActiveTab: ID) {
|
|
209
|
+
if (this.isClaimed()) {
|
|
210
|
+
this.state = 'not-claimed';
|
|
211
|
+
|
|
212
|
+
this.events.onRelease?.();
|
|
213
|
+
|
|
214
|
+
const message: Message = {
|
|
215
|
+
name: 'force-release',
|
|
216
|
+
candidateId: nextActiveTab,
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
this.channel.postMessage(message);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type ID = number;
|
|
2
|
+
|
|
3
|
+
type PingMessage = { name: 'ping'; pingAt: number };
|
|
4
|
+
type PongMessage = { name: 'pong' };
|
|
5
|
+
type ForceClaimMessage = {
|
|
6
|
+
name: 'force-claim';
|
|
7
|
+
candidateId: ID;
|
|
8
|
+
};
|
|
9
|
+
type ForceReleaseMessage = { name: 'force-release'; candidateId: ID };
|
|
10
|
+
|
|
11
|
+
export type Message =
|
|
12
|
+
| PingMessage
|
|
13
|
+
| PongMessage
|
|
14
|
+
| ForceClaimMessage
|
|
15
|
+
| ForceReleaseMessage;
|
|
16
|
+
|
|
17
|
+
export type Events = {
|
|
18
|
+
// Initially attempt to verify if the tab can be activated.
|
|
19
|
+
onInit?: () => void;
|
|
20
|
+
onClaim?: () => void;
|
|
21
|
+
onRelease?: () => void;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export interface TabManagerInterface {
|
|
25
|
+
forceClaim: () => void;
|
|
26
|
+
isClaimed: () => boolean;
|
|
27
|
+
destroy: () => void;
|
|
28
|
+
}
|
|
@@ -20,13 +20,14 @@ import {
|
|
|
20
20
|
} from '@rango-dev/ui';
|
|
21
21
|
import React, { useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
22
22
|
import { flushSync } from 'react-dom';
|
|
23
|
-
import { useNavigate } from 'react-router-dom';
|
|
23
|
+
import { useLocation, useNavigate } from 'react-router-dom';
|
|
24
24
|
|
|
25
25
|
import { getRequiredWallets } from '../components/ConfirmWalletsModal/ConfirmWallets.helpers';
|
|
26
26
|
import { ConfirmWalletsModal } from '../components/ConfirmWalletsModal/ConfirmWalletsModal';
|
|
27
27
|
import { HeaderButton } from '../components/HeaderButtons/HeaderButtons.styles';
|
|
28
28
|
import { RefreshButton } from '../components/HeaderButtons/RefreshButton';
|
|
29
|
-
import { Layout } from '../components/Layout';
|
|
29
|
+
import { Layout, PageContainer } from '../components/Layout';
|
|
30
|
+
import { QuoteWarningsAndErrors } from '../components/QuoteWarningsAndErrors';
|
|
30
31
|
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
31
32
|
import { getQuoteUpdateWarningMessage } from '../constants/warnings';
|
|
32
33
|
import { QuoteInfo } from '../containers/QuoteInfo';
|
|
@@ -37,15 +38,7 @@ import { useUiStore } from '../store/ui';
|
|
|
37
38
|
import { useWalletsStore } from '../store/wallets';
|
|
38
39
|
import { QuoteWarningType } from '../types';
|
|
39
40
|
import { getContainer } from '../utils/common';
|
|
40
|
-
|
|
41
|
-
const Container = styled('div', {
|
|
42
|
-
position: 'relative',
|
|
43
|
-
width: '100%',
|
|
44
|
-
|
|
45
|
-
'& .quote-update__alert': {
|
|
46
|
-
paddingTop: '$10',
|
|
47
|
-
},
|
|
48
|
-
});
|
|
41
|
+
import { joinList } from '../utils/ui';
|
|
49
42
|
|
|
50
43
|
const Buttons = styled('div', {
|
|
51
44
|
width: '100%',
|
|
@@ -88,12 +81,13 @@ export function ConfirmSwapPage() {
|
|
|
88
81
|
quoteWarningsConfirmed,
|
|
89
82
|
} = useQuoteStore();
|
|
90
83
|
const navigate = useNavigate();
|
|
84
|
+
const location = useLocation();
|
|
91
85
|
const [dbErrorMessage, setDbErrorMessage] = useState<string>('');
|
|
92
86
|
|
|
93
87
|
const { connectedWallets } = useWalletsStore();
|
|
94
88
|
const showWalletsOnInit = !quoteWalletsConfirmed;
|
|
95
89
|
const [showWallets, setShowWallets] = useState(false);
|
|
96
|
-
const
|
|
90
|
+
const { isActiveTab } = useUiStore();
|
|
97
91
|
const disabledLiquiditySources = useAppStore().disabledLiquiditySources;
|
|
98
92
|
const prevDisabledLiquiditySources = useRef(disabledLiquiditySources);
|
|
99
93
|
const { manager } = useManager();
|
|
@@ -128,7 +122,6 @@ export function ConfirmSwapPage() {
|
|
|
128
122
|
{ swapDetails: confirmSwapResult.swap },
|
|
129
123
|
{ id: confirmSwapResult.swap.requestId }
|
|
130
124
|
);
|
|
131
|
-
setSelectedSwap(confirmSwapResult.swap.requestId);
|
|
132
125
|
|
|
133
126
|
const swap_url = `../${navigationRoutes.swaps}/${confirmSwapResult.swap.requestId}`;
|
|
134
127
|
navigate(swap_url, {
|
|
@@ -259,10 +252,50 @@ export function ConfirmSwapPage() {
|
|
|
259
252
|
|
|
260
253
|
useLayoutEffect(() => {
|
|
261
254
|
if (!quote) {
|
|
262
|
-
navigate(
|
|
255
|
+
navigate(`../${location.search}`);
|
|
263
256
|
}
|
|
264
257
|
}, []);
|
|
265
258
|
|
|
259
|
+
const quoteWarning = confirmSwapResult.warnings?.quote ?? null;
|
|
260
|
+
const quoteError = confirmSwapResult.error;
|
|
261
|
+
const alerts = [];
|
|
262
|
+
if (dbErrorMessage) {
|
|
263
|
+
alerts.push(<Alert type="error" variant="alarm" title={dbErrorMessage} />);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (confirmSwapResult.warnings?.quoteUpdate) {
|
|
267
|
+
alerts.push(
|
|
268
|
+
<Alert
|
|
269
|
+
variant="alarm"
|
|
270
|
+
type="warning"
|
|
271
|
+
title={
|
|
272
|
+
confirmSwapResult.warnings.quoteUpdate &&
|
|
273
|
+
getQuoteUpdateWarningMessage(confirmSwapResult.warnings.quoteUpdate)
|
|
274
|
+
}
|
|
275
|
+
/>
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if (quoteWarning || quoteError) {
|
|
280
|
+
alerts.push(
|
|
281
|
+
<QuoteWarningsAndErrors
|
|
282
|
+
warning={quoteWarning}
|
|
283
|
+
error={quoteError}
|
|
284
|
+
loading={fetchingConfirmationQuote}
|
|
285
|
+
refetchQuote={onRefresh}
|
|
286
|
+
showWarningModal={showQuoteWarningModal}
|
|
287
|
+
confirmationDisabled={!isActiveTab}
|
|
288
|
+
onOpenWarningModal={() => setShowQuoteWarningModal(true)}
|
|
289
|
+
onCloseWarningModal={() => setShowQuoteWarningModal(false)}
|
|
290
|
+
onConfirmWarningModal={async () => {
|
|
291
|
+
setShowQuoteWarningModal(false);
|
|
292
|
+
await addNewSwap();
|
|
293
|
+
}}
|
|
294
|
+
onChangeSettings={() => navigate(navigationRoutes.settings)}
|
|
295
|
+
/>
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
|
|
266
299
|
return (
|
|
267
300
|
<Layout
|
|
268
301
|
header={{
|
|
@@ -294,7 +327,7 @@ export function ConfirmSwapPage() {
|
|
|
294
327
|
size="large"
|
|
295
328
|
fullWidth
|
|
296
329
|
loading={fetchingConfirmationQuote}
|
|
297
|
-
disabled={!!confirmSwapResult.error}
|
|
330
|
+
disabled={!!confirmSwapResult.error || !isActiveTab}
|
|
298
331
|
onClick={onStartConfirmSwap}>
|
|
299
332
|
{i18n.t('Start Swap')}
|
|
300
333
|
</Button>
|
|
@@ -319,7 +352,7 @@ export function ConfirmSwapPage() {
|
|
|
319
352
|
/>
|
|
320
353
|
)}
|
|
321
354
|
|
|
322
|
-
<
|
|
355
|
+
<PageContainer>
|
|
323
356
|
<div className={descriptionStyles()}>
|
|
324
357
|
<Typography variant="title" size="small">
|
|
325
358
|
{i18n.t('You get')}
|
|
@@ -336,45 +369,20 @@ export function ConfirmSwapPage() {
|
|
|
336
369
|
/>
|
|
337
370
|
</div>
|
|
338
371
|
</div>
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
)}
|
|
345
|
-
{confirmSwapResult.warnings?.quoteUpdate && (
|
|
346
|
-
<div className="quote-update__alert">
|
|
347
|
-
<Alert
|
|
348
|
-
variant="alarm"
|
|
349
|
-
type="warning"
|
|
350
|
-
title={
|
|
351
|
-
confirmSwapResult.warnings.quoteUpdate &&
|
|
352
|
-
getQuoteUpdateWarningMessage(
|
|
353
|
-
confirmSwapResult.warnings.quoteUpdate
|
|
354
|
-
)
|
|
355
|
-
}
|
|
356
|
-
/>
|
|
357
|
-
</div>
|
|
358
|
-
)}
|
|
372
|
+
<Divider size="12" />
|
|
373
|
+
|
|
374
|
+
{joinList(alerts, <Divider size={10} />)}
|
|
375
|
+
{alerts.length > 0 ? <Divider size={10} /> : null}
|
|
376
|
+
|
|
359
377
|
<QuoteInfo
|
|
360
378
|
quote={quote}
|
|
361
379
|
type="swap-preview"
|
|
362
380
|
expanded={true}
|
|
363
|
-
alertPosition="top"
|
|
364
381
|
error={confirmSwapResult.error}
|
|
365
382
|
loading={fetchingConfirmationQuote}
|
|
366
383
|
warning={confirmSwapResult.warnings?.quote ?? null}
|
|
367
|
-
refetchQuote={onRefresh}
|
|
368
|
-
showWarningModal={showQuoteWarningModal}
|
|
369
|
-
onOpenWarningModal={() => setShowQuoteWarningModal(true)}
|
|
370
|
-
onCloseWarningModal={() => setShowQuoteWarningModal(false)}
|
|
371
|
-
onConfirmWarningModal={async () => {
|
|
372
|
-
setShowQuoteWarningModal(false);
|
|
373
|
-
await addNewSwap();
|
|
374
|
-
}}
|
|
375
|
-
onChangeSettings={() => navigate('../' + navigationRoutes.settings)}
|
|
376
384
|
/>
|
|
377
|
-
</
|
|
385
|
+
</PageContainer>
|
|
378
386
|
</Layout>
|
|
379
387
|
);
|
|
380
388
|
}
|
|
@@ -6,23 +6,14 @@ import { Divider, NotFound, styled } from '@rango-dev/ui';
|
|
|
6
6
|
import React, { useState } from 'react';
|
|
7
7
|
import { useNavigate } from 'react-router-dom';
|
|
8
8
|
|
|
9
|
-
import { Layout } from '../components/Layout';
|
|
9
|
+
import { Layout, PageContainer } from '../components/Layout';
|
|
10
10
|
import { SearchInput } from '../components/SearchInput';
|
|
11
11
|
import { SwapsGroup } from '../components/SwapsGroup';
|
|
12
12
|
import { NotFoundContainer } from '../components/SwapsGroup/SwapsGroup.styles';
|
|
13
|
-
import { useUiStore } from '../store/ui';
|
|
14
13
|
import { groupSwapsByDate } from '../utils/date';
|
|
15
14
|
import { containsText } from '../utils/numbers';
|
|
16
15
|
import { getPendingSwaps } from '../utils/queue';
|
|
17
16
|
|
|
18
|
-
const Container = styled('div', {
|
|
19
|
-
display: 'flex',
|
|
20
|
-
flexDirection: 'column',
|
|
21
|
-
alignItems: 'flex-start',
|
|
22
|
-
height: '100%',
|
|
23
|
-
gap: 15,
|
|
24
|
-
});
|
|
25
|
-
|
|
26
17
|
const SwapsGroupContainer = styled('div', {
|
|
27
18
|
overflowY: 'visible',
|
|
28
19
|
width: '100%',
|
|
@@ -46,7 +37,6 @@ const isStepContainsText = (steps: PendingSwapStep[], value: string) => {
|
|
|
46
37
|
};
|
|
47
38
|
|
|
48
39
|
export function HistoryPage() {
|
|
49
|
-
const setSelectedSwap = useUiStore.use.setSelectedSwap();
|
|
50
40
|
const navigate = useNavigate();
|
|
51
41
|
const { manager, state } = useManager();
|
|
52
42
|
const list: PendingSwap[] = getPendingSwaps(manager).map(({ swap }) => swap);
|
|
@@ -76,7 +66,7 @@ export function HistoryPage() {
|
|
|
76
66
|
header={{
|
|
77
67
|
title: i18n.t('History'),
|
|
78
68
|
}}>
|
|
79
|
-
<
|
|
69
|
+
<PageContainer>
|
|
80
70
|
<SearchInput
|
|
81
71
|
setValue={setSearchedFor}
|
|
82
72
|
fullWidth
|
|
@@ -86,6 +76,7 @@ export function HistoryPage() {
|
|
|
86
76
|
onChange={searchHandler}
|
|
87
77
|
value={searchedFor}
|
|
88
78
|
/>
|
|
79
|
+
<Divider size="16" />
|
|
89
80
|
<SwapsGroupContainer>
|
|
90
81
|
{isEmpty && (
|
|
91
82
|
<NotFoundContainer>
|
|
@@ -101,16 +92,13 @@ export function HistoryPage() {
|
|
|
101
92
|
{!isEmpty && (
|
|
102
93
|
<SwapsGroup
|
|
103
94
|
list={filteredList}
|
|
104
|
-
onSwapClick={
|
|
105
|
-
setSelectedSwap(requestId);
|
|
106
|
-
navigate(requestId);
|
|
107
|
-
}}
|
|
95
|
+
onSwapClick={navigate}
|
|
108
96
|
groupBy={groupSwapsByDate}
|
|
109
97
|
isLoading={loading}
|
|
110
98
|
/>
|
|
111
99
|
)}
|
|
112
100
|
</SwapsGroupContainer>
|
|
113
|
-
</
|
|
101
|
+
</PageContainer>
|
|
114
102
|
</Layout>
|
|
115
103
|
);
|
|
116
104
|
}
|
package/src/pages/Home.tsx
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { i18n } from '@lingui/core';
|
|
2
|
-
import { Button, styled, SwapInput, WarningIcon } from '@rango-dev/ui';
|
|
3
|
-
import React, { useEffect,
|
|
2
|
+
import { Button, Divider, styled, SwapInput, WarningIcon } from '@rango-dev/ui';
|
|
3
|
+
import React, { useEffect, useState } from 'react';
|
|
4
4
|
import { useNavigate } from 'react-router-dom';
|
|
5
5
|
|
|
6
6
|
import { HomeButtons } from '../components/HeaderButtons';
|
|
7
|
-
import { Layout } from '../components/Layout';
|
|
7
|
+
import { Layout, PageContainer } from '../components/Layout';
|
|
8
|
+
import { QuoteWarningsAndErrors } from '../components/QuoteWarningsAndErrors';
|
|
8
9
|
import { SwitchFromAndToButton } from '../components/SwitchFromAndTo';
|
|
9
10
|
import { errorMessages } from '../constants/errors';
|
|
10
11
|
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
@@ -28,15 +29,6 @@ import { getPriceImpact, getPriceImpactLevel } from '../utils/quote';
|
|
|
28
29
|
import { canComputePriceImpact, getSwapButtonState } from '../utils/swap';
|
|
29
30
|
import { formatBalance, isFetchingBalance } from '../utils/wallets';
|
|
30
31
|
|
|
31
|
-
const Container = styled('div', {
|
|
32
|
-
display: 'flex',
|
|
33
|
-
flexDirection: 'column',
|
|
34
|
-
overflowY: 'visible',
|
|
35
|
-
'& .quote__container': {
|
|
36
|
-
paddingTop: '$2',
|
|
37
|
-
},
|
|
38
|
-
});
|
|
39
|
-
|
|
40
32
|
const FromContainer = styled('div', {
|
|
41
33
|
position: 'relative',
|
|
42
34
|
});
|
|
@@ -51,7 +43,7 @@ export function Home() {
|
|
|
51
43
|
const navigate = useNavigate();
|
|
52
44
|
const {
|
|
53
45
|
fetch: fetchQuote,
|
|
54
|
-
loading
|
|
46
|
+
loading,
|
|
55
47
|
error: quoteError,
|
|
56
48
|
warning: quoteWarning,
|
|
57
49
|
} = useSwapInput();
|
|
@@ -73,9 +65,8 @@ export function Home() {
|
|
|
73
65
|
const fetchMetaStatus = useAppStore().fetchStatus;
|
|
74
66
|
|
|
75
67
|
const { connectedWallets, getBalanceFor } = useWalletsStore();
|
|
76
|
-
const
|
|
68
|
+
const { isActiveTab } = useUiStore();
|
|
77
69
|
const [showQuoteWarningModal, setShowQuoteWarningModal] = useState(false);
|
|
78
|
-
const layoutRef = useRef<HTMLDivElement>(null);
|
|
79
70
|
const fetchingBalance =
|
|
80
71
|
!!fromBlockchain &&
|
|
81
72
|
isFetchingBalance(connectedWallets, fromBlockchain.name);
|
|
@@ -96,7 +87,7 @@ export function Home() {
|
|
|
96
87
|
|
|
97
88
|
const swapButtonState = getSwapButtonState({
|
|
98
89
|
fetchMetaStatus,
|
|
99
|
-
fetchingQuote,
|
|
90
|
+
fetchingQuote: loading,
|
|
100
91
|
inputAmount,
|
|
101
92
|
quote,
|
|
102
93
|
anyWalletConnected: connectedWallets.length > 0,
|
|
@@ -115,10 +106,15 @@ export function Home() {
|
|
|
115
106
|
? numberToString(fromTokenBalance?.amount, fromTokenBalance?.decimals)
|
|
116
107
|
: '0';
|
|
117
108
|
|
|
109
|
+
const fetchingQuote =
|
|
110
|
+
fetchMetaStatus === 'success' &&
|
|
111
|
+
!!inputAmount &&
|
|
112
|
+
!!fromToken &&
|
|
113
|
+
!!toToken &&
|
|
114
|
+
loading;
|
|
115
|
+
|
|
118
116
|
useEffect(() => {
|
|
119
|
-
setCurrentPage(navigationRoutes.home);
|
|
120
117
|
resetQuoteWallets();
|
|
121
|
-
return setCurrentPage.bind(null, '');
|
|
122
118
|
}, []);
|
|
123
119
|
|
|
124
120
|
const percentageChange =
|
|
@@ -128,14 +124,13 @@ export function Home() {
|
|
|
128
124
|
|
|
129
125
|
return (
|
|
130
126
|
<Layout
|
|
131
|
-
|
|
132
|
-
fixedHeight={false}
|
|
127
|
+
height="auto"
|
|
133
128
|
hasLogo
|
|
134
129
|
footer={
|
|
135
130
|
<Button
|
|
136
131
|
type="primary"
|
|
137
132
|
size="large"
|
|
138
|
-
disabled={swapButtonState.disabled}
|
|
133
|
+
disabled={swapButtonState.disabled || !isActiveTab}
|
|
139
134
|
prefix={
|
|
140
135
|
swapButtonState.action === 'confirm-warning' && <WarningIcon />
|
|
141
136
|
}
|
|
@@ -160,7 +155,6 @@ export function Home() {
|
|
|
160
155
|
title: i18n.t('Swap'),
|
|
161
156
|
suffix: (
|
|
162
157
|
<HomeButtons
|
|
163
|
-
layoutRef={layoutRef.current}
|
|
164
158
|
onClickRefresh={
|
|
165
159
|
(!!quote || quoteError) && !showQuoteWarningModal
|
|
166
160
|
? fetchQuote
|
|
@@ -171,7 +165,7 @@ export function Home() {
|
|
|
171
165
|
/>
|
|
172
166
|
),
|
|
173
167
|
}}>
|
|
174
|
-
<
|
|
168
|
+
<PageContainer>
|
|
175
169
|
<InputsContainer>
|
|
176
170
|
<FromContainer>
|
|
177
171
|
<SwapInput
|
|
@@ -262,26 +256,36 @@ export function Home() {
|
|
|
262
256
|
tooltipContainer={getContainer()}
|
|
263
257
|
/>
|
|
264
258
|
</InputsContainer>
|
|
265
|
-
<
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
259
|
+
<Divider size="2" />
|
|
260
|
+
<QuoteInfo
|
|
261
|
+
quote={quote}
|
|
262
|
+
loading={fetchingQuote}
|
|
263
|
+
error={quoteError}
|
|
264
|
+
warning={quoteWarning}
|
|
265
|
+
type="basic"
|
|
266
|
+
/>
|
|
267
|
+
{quoteWarning || quoteError ? (
|
|
268
|
+
<>
|
|
269
|
+
<Divider size="10" />
|
|
270
|
+
<QuoteWarningsAndErrors
|
|
271
|
+
warning={quoteWarning}
|
|
272
|
+
error={quoteError}
|
|
273
|
+
loading={fetchingQuote}
|
|
274
|
+
refetchQuote={fetchQuote}
|
|
275
|
+
showWarningModal={showQuoteWarningModal}
|
|
276
|
+
confirmationDisabled={!isActiveTab}
|
|
277
|
+
onOpenWarningModal={() => setShowQuoteWarningModal(true)}
|
|
278
|
+
onCloseWarningModal={() => setShowQuoteWarningModal(false)}
|
|
279
|
+
onConfirmWarningModal={() => {
|
|
280
|
+
setShowQuoteWarningModal(false);
|
|
281
|
+
setQuoteWarningsConfirmed(true);
|
|
282
|
+
navigate(navigationRoutes.confirmSwap);
|
|
283
|
+
}}
|
|
284
|
+
onChangeSettings={() => navigate(navigationRoutes.settings)}
|
|
285
|
+
/>
|
|
286
|
+
</>
|
|
287
|
+
) : null}
|
|
288
|
+
</PageContainer>
|
|
285
289
|
</Layout>
|
|
286
290
|
);
|
|
287
291
|
}
|
|
@@ -8,8 +8,7 @@ import {
|
|
|
8
8
|
} from '@rango-dev/ui';
|
|
9
9
|
import React from 'react';
|
|
10
10
|
|
|
11
|
-
import { Layout } from '../components/Layout';
|
|
12
|
-
import { SettingsContainer } from '../components/SettingsContainer';
|
|
11
|
+
import { Layout, PageContainer } from '../components/Layout';
|
|
13
12
|
import { useLanguage } from '../hooks/useLanguage';
|
|
14
13
|
|
|
15
14
|
export function LanguagePage() {
|
|
@@ -36,7 +35,7 @@ export function LanguagePage() {
|
|
|
36
35
|
header={{
|
|
37
36
|
title: i18n.t('Language'),
|
|
38
37
|
}}>
|
|
39
|
-
<
|
|
38
|
+
<PageContainer>
|
|
40
39
|
<RadioRoot value={activeLanguage}>
|
|
41
40
|
<List
|
|
42
41
|
type={
|
|
@@ -49,7 +48,7 @@ export function LanguagePage() {
|
|
|
49
48
|
items={languageList}
|
|
50
49
|
/>
|
|
51
50
|
</RadioRoot>
|
|
52
|
-
</
|
|
51
|
+
</PageContainer>
|
|
53
52
|
</Layout>
|
|
54
53
|
);
|
|
55
54
|
}
|