@rango-dev/widget-embedded 0.1.11-next.12 → 0.1.11-next.14
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/components/ConfirmSwapErrors.d.ts +1 -1
- package/dist/components/ConfirmSwapErrors.d.ts.map +1 -1
- package/dist/components/ConfirmSwapWarnings.d.ts +1 -2
- package/dist/components/ConfirmSwapWarnings.d.ts.map +1 -1
- package/dist/components/warnings/BalanceErrors.d.ts +7 -0
- package/dist/components/warnings/BalanceErrors.d.ts.map +1 -0
- package/dist/pages/Home.d.ts.map +1 -1
- package/dist/store/bestRoute.d.ts.map +1 -1
- package/dist/types/routing.d.ts +8 -8
- package/dist/types/routing.d.ts.map +1 -1
- package/dist/utils/numbers.d.ts +1 -0
- package/dist/utils/numbers.d.ts.map +1 -1
- package/dist/utils/time.d.ts.map +1 -1
- package/dist/widget-embedded.cjs.development.js +53 -62
- package/dist/widget-embedded.cjs.development.js.map +1 -1
- package/dist/widget-embedded.cjs.production.min.js +53 -62
- package/dist/widget-embedded.cjs.production.min.js.map +1 -1
- package/dist/widget-embedded.esm.js +53 -62
- package/dist/widget-embedded.esm.js.map +1 -1
- package/package.json +2 -2
- package/src/components/ConfirmSwapErrors.tsx +8 -16
- package/src/components/ConfirmSwapWarnings.tsx +5 -15
- package/src/components/warnings/BalanceErrors.tsx +45 -0
- package/src/hooks/useConfirmSwap.ts +2 -2
- package/src/pages/Home.tsx +4 -7
- package/src/pages/SwapDetailsPage.tsx +1 -1
- package/src/pages/WalletsPage.tsx +1 -1
- package/src/store/bestRoute.ts +5 -3
- package/src/types/routing.ts +4 -4
- package/src/utils/numbers.ts +4 -0
- package/src/utils/time.ts +2 -8
- package/dist/components/warnings/BalanceWarnings.d.ts +0 -7
- package/dist/components/warnings/BalanceWarnings.d.ts.map +0 -1
- package/src/components/warnings/BalanceWarnings.tsx +0 -40
|
@@ -117,6 +117,7 @@ const decimalNumber = function (number, toFixed) {
|
|
|
117
117
|
}
|
|
118
118
|
return parseFloat(number).toFixed(toFixed);
|
|
119
119
|
};
|
|
120
|
+
const isPositiveNumber = text => !!text && parseFloat(text) > 0;
|
|
120
121
|
|
|
121
122
|
function searchParamsToToken(tokens, searchParams, chain) {
|
|
122
123
|
if (!chain) return null;
|
|
@@ -942,7 +943,7 @@ const useBestRouteStore = /*#__PURE__*/createSelectors( /*#__PURE__*/create()( /
|
|
|
942
943
|
setBestRoute: bestRoute => set(state => {
|
|
943
944
|
let outputAmount = null;
|
|
944
945
|
let outputUsdValue = ZERO;
|
|
945
|
-
if (!state.inputAmount
|
|
946
|
+
if (!isPositiveNumber(state.inputAmount)) return {};
|
|
946
947
|
if (!!bestRoute) {
|
|
947
948
|
outputAmount = !!bestRoute.result?.outputAmount ? new BigNumber(bestRoute.result?.outputAmount) : null;
|
|
948
949
|
outputUsdValue = calcOutputUsdValue(bestRoute.result?.outputAmount, getBestRouteToTokenUsdPrice(bestRoute) || state.toToken?.usdPrice);
|
|
@@ -1077,7 +1078,7 @@ const bestRoute = (bestRouteStore, settingsStore) => {
|
|
|
1077
1078
|
disabledLiquiditySources,
|
|
1078
1079
|
affiliateRef
|
|
1079
1080
|
} = settingsStore.getState();
|
|
1080
|
-
if (!fromToken || !toToken || !inputAmount
|
|
1081
|
+
if (!fromToken || !toToken || !isPositiveNumber(inputAmount)) return;
|
|
1081
1082
|
abortController?.abort();
|
|
1082
1083
|
abortController = new AbortController();
|
|
1083
1084
|
const userSlippage = !!customSlippage ? customSlippage : slippage;
|
|
@@ -1115,7 +1116,7 @@ const bestRoute = (bestRouteStore, settingsStore) => {
|
|
|
1115
1116
|
inputAmount,
|
|
1116
1117
|
inputUsdValue
|
|
1117
1118
|
} = useBestRouteStore.getState();
|
|
1118
|
-
if (!inputAmount ||
|
|
1119
|
+
if (!isPositiveNumber(inputAmount) || inputUsdValue.eq(0)) return bestRouteStore.setState({
|
|
1119
1120
|
loading: false
|
|
1120
1121
|
});
|
|
1121
1122
|
if (tokensAreEqual(fromToken, toToken)) return bestRouteStore.setState({
|
|
@@ -1770,11 +1771,9 @@ function Home() {
|
|
|
1770
1771
|
type: "error",
|
|
1771
1772
|
title: `${swap?.swapperId} Limit`
|
|
1772
1773
|
}, React.createElement(React.Fragment, null, React.createElement(Typography, {
|
|
1773
|
-
variant: "
|
|
1774
|
-
}, fromAmountRangeError
|
|
1775
|
-
variant: "
|
|
1776
|
-
}, "Yours: ", numberToString(swap?.fromAmount || null), swap?.from.symbol), React.createElement("br", null), React.createElement(Typography, {
|
|
1777
|
-
variant: "body2"
|
|
1774
|
+
variant: "body3"
|
|
1775
|
+
}, fromAmountRangeError, ", Yours: ", numberToString(swap?.fromAmount || null), "\u00A0", swap?.from.symbol), React.createElement(Typography, {
|
|
1776
|
+
variant: "body3"
|
|
1778
1777
|
}, recommendation)))), React.createElement(Footer, null, React.createElement(Button, {
|
|
1779
1778
|
type: "primary",
|
|
1780
1779
|
align: "grow",
|
|
@@ -2028,6 +2027,7 @@ var ConfirmSwapErrorTypes;
|
|
|
2028
2027
|
ConfirmSwapErrorTypes[ConfirmSwapErrorTypes["ROUTE_UPDATED_WITH_HIGH_VALUE_LOSS"] = 1] = "ROUTE_UPDATED_WITH_HIGH_VALUE_LOSS";
|
|
2029
2028
|
ConfirmSwapErrorTypes[ConfirmSwapErrorTypes["REQUEST_FAILED"] = 2] = "REQUEST_FAILED";
|
|
2030
2029
|
ConfirmSwapErrorTypes[ConfirmSwapErrorTypes["INSUFFICIENT_SLIPPAGE"] = 3] = "INSUFFICIENT_SLIPPAGE";
|
|
2030
|
+
ConfirmSwapErrorTypes[ConfirmSwapErrorTypes["INSUFFICIENT_BALANCE"] = 4] = "INSUFFICIENT_BALANCE";
|
|
2031
2031
|
})(ConfirmSwapErrorTypes || (ConfirmSwapErrorTypes = {}));
|
|
2032
2032
|
var ConfirmSwapWarningTypes;
|
|
2033
2033
|
(function (ConfirmSwapWarningTypes) {
|
|
@@ -2035,7 +2035,6 @@ var ConfirmSwapWarningTypes;
|
|
|
2035
2035
|
ConfirmSwapWarningTypes[ConfirmSwapWarningTypes["ROUTE_SWAPPERS_UPDATED"] = 1] = "ROUTE_SWAPPERS_UPDATED";
|
|
2036
2036
|
ConfirmSwapWarningTypes[ConfirmSwapWarningTypes["ROUTE_COINS_UPDATED"] = 2] = "ROUTE_COINS_UPDATED";
|
|
2037
2037
|
ConfirmSwapWarningTypes[ConfirmSwapWarningTypes["ROUTE_AND_OUTPUT_AMOUNT_UPDATED"] = 3] = "ROUTE_AND_OUTPUT_AMOUNT_UPDATED";
|
|
2038
|
-
ConfirmSwapWarningTypes[ConfirmSwapWarningTypes["INSUFFICIENT_BALANCE"] = 4] = "INSUFFICIENT_BALANCE";
|
|
2039
2038
|
})(ConfirmSwapWarningTypes || (ConfirmSwapWarningTypes = {}));
|
|
2040
2039
|
|
|
2041
2040
|
function useConfirmSwap() {
|
|
@@ -2124,8 +2123,8 @@ function useConfirmSwap() {
|
|
|
2124
2123
|
}
|
|
2125
2124
|
const balanceWarnings = getBalanceWarnings(confiremedRoute, selectedWallets);
|
|
2126
2125
|
const enoughBalance = balanceWarnings.length === 0;
|
|
2127
|
-
if (!enoughBalance) confirmSwapState.
|
|
2128
|
-
type:
|
|
2126
|
+
if (!enoughBalance) confirmSwapState.errors.push({
|
|
2127
|
+
type: ConfirmSwapErrorTypes.INSUFFICIENT_BALANCE,
|
|
2129
2128
|
messages: balanceWarnings
|
|
2130
2129
|
});
|
|
2131
2130
|
const minRequiredSlippage = getMinRequiredSlippage(initialRoute);
|
|
@@ -2195,31 +2194,6 @@ function MinRequiredSlippage(_ref) {
|
|
|
2195
2194
|
}), React.createElement(ChangeSlippageButton, null));
|
|
2196
2195
|
}
|
|
2197
2196
|
|
|
2198
|
-
function ConfirmSwapErrors(errors) {
|
|
2199
|
-
return errors.flatMap(error => {
|
|
2200
|
-
switch (error.type) {
|
|
2201
|
-
case ConfirmSwapErrorTypes.NO_ROUTE:
|
|
2202
|
-
return React.createElement(Typography, {
|
|
2203
|
-
variant: "body2"
|
|
2204
|
-
}, "No routes found. Please try again later.");
|
|
2205
|
-
case ConfirmSwapErrorTypes.REQUEST_FAILED:
|
|
2206
|
-
return React.createElement(Typography, {
|
|
2207
|
-
variant: "body2"
|
|
2208
|
-
}, `Failed to confirm swap ${error.status ? `'status': ${error.status})` : ''}, please try again.`);
|
|
2209
|
-
case ConfirmSwapErrorTypes.ROUTE_UPDATED_WITH_HIGH_VALUE_LOSS:
|
|
2210
|
-
return React.createElement(Typography, {
|
|
2211
|
-
variant: "body2"
|
|
2212
|
-
}, "Route updated and price impact is too high, try again later!");
|
|
2213
|
-
case ConfirmSwapErrorTypes.INSUFFICIENT_SLIPPAGE:
|
|
2214
|
-
return React.createElement(MinRequiredSlippage, {
|
|
2215
|
-
minRequiredSlippage: error.minRequiredSlippage
|
|
2216
|
-
});
|
|
2217
|
-
default:
|
|
2218
|
-
return [];
|
|
2219
|
-
}
|
|
2220
|
-
});
|
|
2221
|
-
}
|
|
2222
|
-
|
|
2223
2197
|
const List = /*#__PURE__*/styled('ul', {
|
|
2224
2198
|
variants: {
|
|
2225
2199
|
showListStyle: {
|
|
@@ -2240,47 +2214,63 @@ const ListItem = /*#__PURE__*/styled('li', {
|
|
|
2240
2214
|
}
|
|
2241
2215
|
});
|
|
2242
2216
|
const Message = /*#__PURE__*/styled(Typography, {
|
|
2243
|
-
display: 'block'
|
|
2244
|
-
color: '$warning500 !important'
|
|
2217
|
+
display: 'block'
|
|
2245
2218
|
});
|
|
2246
|
-
function
|
|
2219
|
+
function BalanceErrors(_ref) {
|
|
2247
2220
|
let {
|
|
2248
2221
|
messages
|
|
2249
2222
|
} = _ref;
|
|
2250
2223
|
const showListStyle = messages.length > 1;
|
|
2251
|
-
return React.createElement(
|
|
2224
|
+
return React.createElement(React.Fragment, null, React.createElement(Typography, {
|
|
2225
|
+
className: "title",
|
|
2226
|
+
variant: "title",
|
|
2227
|
+
color: 'error'
|
|
2228
|
+
}, "Insufficent Balance:"), React.createElement(Spacer, {
|
|
2229
|
+
size: 8,
|
|
2230
|
+
direction: "vertical"
|
|
2231
|
+
}), React.createElement(List, {
|
|
2252
2232
|
showListStyle: showListStyle
|
|
2253
2233
|
}, messages.map(warning => React.createElement(ListItem, {
|
|
2254
2234
|
showListStyle: showListStyle
|
|
2255
2235
|
}, React.createElement(Message, {
|
|
2256
|
-
variant: "
|
|
2257
|
-
}, warning))));
|
|
2236
|
+
variant: "body3"
|
|
2237
|
+
}, "- ", warning)))));
|
|
2238
|
+
}
|
|
2239
|
+
|
|
2240
|
+
function ConfirmSwapErrors(errors) {
|
|
2241
|
+
return errors.flatMap(error => {
|
|
2242
|
+
switch (error.type) {
|
|
2243
|
+
case ConfirmSwapErrorTypes.NO_ROUTE:
|
|
2244
|
+
return "No routes found. Please try again later.";
|
|
2245
|
+
case ConfirmSwapErrorTypes.REQUEST_FAILED:
|
|
2246
|
+
return `Failed to confirm swap ${error.status ? `'status': ${error.status})` : ''}, please try again.`;
|
|
2247
|
+
case ConfirmSwapErrorTypes.ROUTE_UPDATED_WITH_HIGH_VALUE_LOSS:
|
|
2248
|
+
return "Route updated and price impact is too high, try again later!";
|
|
2249
|
+
case ConfirmSwapErrorTypes.INSUFFICIENT_SLIPPAGE:
|
|
2250
|
+
return React.createElement(MinRequiredSlippage, {
|
|
2251
|
+
minRequiredSlippage: error.minRequiredSlippage
|
|
2252
|
+
});
|
|
2253
|
+
case ConfirmSwapErrorTypes.INSUFFICIENT_BALANCE:
|
|
2254
|
+
return React.createElement(BalanceErrors, {
|
|
2255
|
+
messages: error.messages
|
|
2256
|
+
});
|
|
2257
|
+
default:
|
|
2258
|
+
return [];
|
|
2259
|
+
}
|
|
2260
|
+
});
|
|
2258
2261
|
}
|
|
2259
2262
|
|
|
2260
2263
|
function ConfirmSwapWarnings(warnings) {
|
|
2261
2264
|
return warnings.flatMap(warning => {
|
|
2262
2265
|
switch (warning.type) {
|
|
2263
2266
|
case ConfirmSwapWarningTypes.ROUTE_UPDATED:
|
|
2264
|
-
return
|
|
2265
|
-
variant: "body2"
|
|
2266
|
-
}, "Route has been updated.");
|
|
2267
|
+
return "Route has been updated.";
|
|
2267
2268
|
case ConfirmSwapWarningTypes.ROUTE_AND_OUTPUT_AMOUNT_UPDATED:
|
|
2268
|
-
return
|
|
2269
|
-
variant: "body2"
|
|
2270
|
-
}, `Output amount changed to ${warning.newOutputAmount}
|
|
2271
|
-
(${warning.percentageChange}% change).`);
|
|
2269
|
+
return `Output amount changed to ${warning.newOutputAmount} (${warning.percentageChange}% change).`;
|
|
2272
2270
|
case ConfirmSwapWarningTypes.ROUTE_SWAPPERS_UPDATED:
|
|
2273
|
-
return
|
|
2274
|
-
variant: "body2"
|
|
2275
|
-
}, "Route swappers has been updated.");
|
|
2271
|
+
return "Route swappers has been updated.";
|
|
2276
2272
|
case ConfirmSwapWarningTypes.ROUTE_COINS_UPDATED:
|
|
2277
|
-
return
|
|
2278
|
-
variant: "body2"
|
|
2279
|
-
}, "Route internal coins has been updated.");
|
|
2280
|
-
case ConfirmSwapWarningTypes.INSUFFICIENT_BALANCE:
|
|
2281
|
-
return React.createElement(BalanceWarnings, {
|
|
2282
|
-
messages: warning.messages
|
|
2283
|
-
});
|
|
2273
|
+
return "Route internal coins has been updated.";
|
|
2284
2274
|
default:
|
|
2285
2275
|
return [];
|
|
2286
2276
|
}
|
|
@@ -2728,8 +2718,9 @@ function WalletsPage(_ref) {
|
|
|
2728
2718
|
textField: false,
|
|
2729
2719
|
onBack: navigateBackFrom.bind(null, navigationRoutes.wallets)
|
|
2730
2720
|
}, React.createElement(React.Fragment, null, walletErrorMessage && React.createElement(AlertContainer, null, React.createElement(Alert, {
|
|
2731
|
-
type: "error"
|
|
2732
|
-
|
|
2721
|
+
type: "error",
|
|
2722
|
+
title: walletErrorMessage
|
|
2723
|
+
})), loadingMetaStatus === 'loading' && React.createElement(LoaderContainer, {
|
|
2733
2724
|
className: "loader"
|
|
2734
2725
|
}, React.createElement(Spinner, {
|
|
2735
2726
|
size: 24
|
|
@@ -2793,7 +2784,7 @@ function timeSince(timeMillis) {
|
|
|
2793
2784
|
return interval + ' ' + intervalType;
|
|
2794
2785
|
}
|
|
2795
2786
|
function getSwapDate(pendingSwap) {
|
|
2796
|
-
return pendingSwap.finishTime ?
|
|
2787
|
+
return pendingSwap.finishTime ? `${timeSince(parseInt(pendingSwap.finishTime))} ago` : `${timeSince(parseInt(pendingSwap.creationTime))} ago`;
|
|
2797
2788
|
}
|
|
2798
2789
|
|
|
2799
2790
|
const PlaceholderContainer = /*#__PURE__*/styled('div', {
|