@rango-dev/queue-manager-rango-preset 0.1.10 → 0.1.11-next.3
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/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/numbers.d.ts +3 -0
- package/dist/numbers.d.ts.map +1 -0
- package/dist/queue-manager-rango-preset.cjs.development.js +132 -1
- package/dist/queue-manager-rango-preset.cjs.development.js.map +1 -1
- package/dist/queue-manager-rango-preset.cjs.production.min.js +1 -1
- package/dist/queue-manager-rango-preset.cjs.production.min.js.map +1 -1
- package/dist/queue-manager-rango-preset.esm.js +130 -2
- package/dist/queue-manager-rango-preset.esm.js.map +1 -1
- package/dist/services/httpService.d.ts.map +1 -1
- package/dist/shared-sentry.d.ts +1 -1
- package/dist/shared-sentry.d.ts.map +1 -1
- package/dist/shared.d.ts +16 -5
- package/dist/shared.d.ts.map +1 -1
- package/package.json +1 -1
- package/readme.md +1 -1
- package/src/index.ts +1 -0
- package/src/numbers.ts +68 -0
- package/src/services/httpService.ts +5 -1
- package/src/shared-sentry.ts +1 -1
- package/src/shared.ts +153 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { PrettyError, prettifyErrorMessage } from './shared-errors';
|
|
2
2
|
export { SwapQueueContext, SwapStorage } from './types';
|
|
3
|
-
export { PendingSwapWithQueueID, getCurrentBlockchainOfOrNull, getRelatedWalletOrNull, getRelatedWallet, MessageSeverity, PendingSwapStep, PendingSwapNetworkStatus, PendingSwap, EventType, SwapProgressNotification, } from './shared';
|
|
3
|
+
export { PendingSwapWithQueueID, getCurrentBlockchainOfOrNull, getRelatedWalletOrNull, getRelatedWallet, MessageSeverity, PendingSwapStep, PendingSwapNetworkStatus, PendingSwap, EventType, SwapProgressNotification, calculatePendingSwap, } from './shared';
|
|
4
4
|
export { updateSwapStatus, checkWaitingForNetworkChange, getCurrentStep, getEvmProvider, cancelSwap, getRequiredWallet, getRunningSwaps, splitWalletNetwork, resetRunningSwapNotifsOnPageLoad, } from './helpers';
|
|
5
5
|
export { swapQueueDef } from './queueDef';
|
|
6
6
|
export { useMigration, useQueueManager } from './hooks';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACxD,OAAO,EACL,sBAAsB,EACtB,4BAA4B,EAC5B,sBAAsB,EACtB,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,wBAAwB,EACxB,WAAW,EACX,SAAS,EACT,wBAAwB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACxD,OAAO,EACL,sBAAsB,EACtB,4BAA4B,EAC5B,sBAAsB,EACtB,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,wBAAwB,EACxB,WAAW,EACX,SAAS,EACT,wBAAwB,EACxB,oBAAoB,GACrB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,gBAAgB,EAChB,4BAA4B,EAC5B,cAAc,EACd,cAAc,EACd,UAAU,EACV,iBAAiB,EACjB,eAAe,EACf,kBAAkB,EAClB,gCAAgC,GACjC,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"numbers.d.ts","sourceRoot":"","sources":["src/numbers.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC,eAAO,MAAM,cAAc,WACjB,SAAS,GAAG,MAAM,GAAG,IAAI,gBACpB,MAAM,GAAG,IAAI,gBACb,MAAM,GAAG,IAAI,KACzB,MA6DF,CAAC"}
|
|
@@ -2,8 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
6
|
+
|
|
5
7
|
var rangoTypes = require('rango-types');
|
|
6
8
|
var walletsShared = require('@rango-dev/wallets-shared');
|
|
9
|
+
var BigNumber = _interopDefault(require('bignumber.js'));
|
|
7
10
|
var walletsCore = require('@rango-dev/wallets-core');
|
|
8
11
|
var rangoSdk = require('rango-sdk');
|
|
9
12
|
var queueManagerCore = require('@rango-dev/queue-manager-core');
|
|
@@ -526,6 +529,34 @@ var prettifyErrorMessage = function prettifyErrorMessage(obj) {
|
|
|
526
529
|
};
|
|
527
530
|
};
|
|
528
531
|
|
|
532
|
+
var numberToString = function numberToString(number, minDecimals, maxDecimals) {
|
|
533
|
+
if (minDecimals === void 0) {
|
|
534
|
+
minDecimals = null;
|
|
535
|
+
}
|
|
536
|
+
if (maxDecimals === void 0) {
|
|
537
|
+
maxDecimals = null;
|
|
538
|
+
}
|
|
539
|
+
if (number === null) return '';
|
|
540
|
+
if (number === '') return '';
|
|
541
|
+
var n = new BigNumber(number);
|
|
542
|
+
var roundingMode = 1;
|
|
543
|
+
var maxI = 1000;
|
|
544
|
+
for (var i = 0; i < 60; i++) {
|
|
545
|
+
if (new BigNumber(n.toFixed(i, roundingMode)).eq(n)) {
|
|
546
|
+
maxI = i;
|
|
547
|
+
break;
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
if (n.gte(10000)) return n.toFormat(0, roundingMode);
|
|
551
|
+
if (n.gte(1000)) return n.toFormat(Math.min(maxI, Math.min(maxDecimals || 100, Math.max(minDecimals || 0, 1))), roundingMode);
|
|
552
|
+
if (n.gte(100)) return n.toFormat(Math.min(maxI, Math.min(maxDecimals || 100, Math.max(minDecimals || 0, 1))), roundingMode);
|
|
553
|
+
if (n.gte(1)) return n.toFormat(Math.min(maxI, Math.min(maxDecimals || 100, Math.max(minDecimals || 0, 2))), roundingMode);
|
|
554
|
+
if (n.gte(0.01)) return n.toFormat(Math.min(maxI, Math.min(maxDecimals || 100, Math.max(minDecimals || 0, 4))), roundingMode);
|
|
555
|
+
for (var _i = minDecimals || 4; _i < 17; _i++) if (n.gte(Math.pow(10, -_i))) return n.toFormat(Math.min(maxI, Math.min(maxDecimals || 100, Math.max(minDecimals || 0, _i))), roundingMode);
|
|
556
|
+
if (n.isEqualTo(0)) return '0';
|
|
557
|
+
return n.toFormat(Math.min(maxI, Math.min(maxDecimals || 100, Math.max(minDecimals || 0, 8))), roundingMode);
|
|
558
|
+
};
|
|
559
|
+
|
|
529
560
|
(function (PendingSwapNetworkStatus) {
|
|
530
561
|
PendingSwapNetworkStatus["WaitingForConnectingWallet"] = "waitingForConnectingWallet";
|
|
531
562
|
PendingSwapNetworkStatus["WaitingForQueue"] = "waitingForQueue";
|
|
@@ -615,6 +646,102 @@ function getRelatedWalletOrNull(swap, currentStep) {
|
|
|
615
646
|
return null;
|
|
616
647
|
}
|
|
617
648
|
}
|
|
649
|
+
var getUsdPrice = function getUsdPrice(blockchain, symbol, address, allTokens) {
|
|
650
|
+
var token = allTokens == null ? void 0 : allTokens.find(function (t) {
|
|
651
|
+
var _t$symbol;
|
|
652
|
+
return t.blockchain === blockchain && ((_t$symbol = t.symbol) == null ? void 0 : _t$symbol.toUpperCase()) === (symbol == null ? void 0 : symbol.toUpperCase()) && t.address === address;
|
|
653
|
+
});
|
|
654
|
+
return (token == null ? void 0 : token.usdPrice) || null;
|
|
655
|
+
};
|
|
656
|
+
function getUsdFeeOfStep(step, allTokens) {
|
|
657
|
+
var totalFeeInUsd = new BigNumber(0);
|
|
658
|
+
for (var i = 0; i < step.fee.length; i++) {
|
|
659
|
+
var fee = step.fee[i];
|
|
660
|
+
if (fee.expenseType === 'DECREASE_FROM_OUTPUT') continue;
|
|
661
|
+
var unitPrice = getUsdPrice(fee.asset.blockchain, fee.asset.symbol, fee.asset.address, allTokens);
|
|
662
|
+
totalFeeInUsd = totalFeeInUsd.plus(new BigNumber(fee.amount).multipliedBy(unitPrice || 0));
|
|
663
|
+
}
|
|
664
|
+
return totalFeeInUsd;
|
|
665
|
+
}
|
|
666
|
+
function calculatePendingSwap(inputAmount, bestRoute, wallets, settings, validateBalanceOrFee, meta) {
|
|
667
|
+
var _bestRoute$result, _bestRoute$result$swa;
|
|
668
|
+
var simulationResult = bestRoute.result;
|
|
669
|
+
if (!simulationResult) throw Error('Simulation result should not be null');
|
|
670
|
+
return {
|
|
671
|
+
creationTime: new Date().getTime().toString(),
|
|
672
|
+
finishTime: null,
|
|
673
|
+
requestId: bestRoute.requestId || '',
|
|
674
|
+
inputAmount: inputAmount,
|
|
675
|
+
wallets: wallets,
|
|
676
|
+
status: 'running',
|
|
677
|
+
isPaused: false,
|
|
678
|
+
extraMessage: null,
|
|
679
|
+
extraMessageSeverity: null,
|
|
680
|
+
extraMessageDetail: null,
|
|
681
|
+
extraMessageErrorCode: null,
|
|
682
|
+
networkStatusExtraMessage: null,
|
|
683
|
+
networkStatusExtraMessageDetail: null,
|
|
684
|
+
lastNotificationTime: null,
|
|
685
|
+
settings: settings,
|
|
686
|
+
simulationResult: simulationResult,
|
|
687
|
+
validateBalanceOrFee: validateBalanceOrFee,
|
|
688
|
+
steps: ((_bestRoute$result = bestRoute.result) == null ? void 0 : (_bestRoute$result$swa = _bestRoute$result.swaps) == null ? void 0 : _bestRoute$result$swa.map(function (swap, index) {
|
|
689
|
+
return {
|
|
690
|
+
id: index + 1,
|
|
691
|
+
// from
|
|
692
|
+
fromBlockchain: swap.from.blockchain,
|
|
693
|
+
fromBlockchainLogo: swap.from.blockchainLogo,
|
|
694
|
+
fromLogo: swap.from.logo,
|
|
695
|
+
fromSymbol: swap.from.symbol,
|
|
696
|
+
fromSymbolAddress: swap.from.address,
|
|
697
|
+
fromDecimals: swap.from.decimals,
|
|
698
|
+
fromAmountPrecision: swap.fromAmountPrecision,
|
|
699
|
+
fromAmountMinValue: swap.fromAmountMinValue,
|
|
700
|
+
fromAmountMaxValue: swap.fromAmountMaxValue,
|
|
701
|
+
fromAmountRestrictionType: swap.fromAmountRestrictionType,
|
|
702
|
+
// to
|
|
703
|
+
toBlockchain: swap.to.blockchain,
|
|
704
|
+
toBlockchainLogo: swap.to.blockchainLogo,
|
|
705
|
+
toSymbol: swap.to.symbol,
|
|
706
|
+
toSymbolAddress: swap.to.address,
|
|
707
|
+
toDecimals: swap.to.decimals,
|
|
708
|
+
toLogo: swap.to.logo,
|
|
709
|
+
// swapper
|
|
710
|
+
swapperId: swap.swapperId,
|
|
711
|
+
swapperLogo: swap.swapperLogo,
|
|
712
|
+
swapperType: swap.swapperType,
|
|
713
|
+
// output, fee, timing
|
|
714
|
+
expectedOutputAmountHumanReadable: swap.toAmount,
|
|
715
|
+
outputAmount: '',
|
|
716
|
+
feeInUsd: meta ? numberToString(getUsdFeeOfStep(swap, meta == null ? void 0 : meta.tokens), null, 8) : null,
|
|
717
|
+
estimatedTimeInSeconds: swap.estimatedTimeInSeconds || null,
|
|
718
|
+
// status, tracking
|
|
719
|
+
status: 'created',
|
|
720
|
+
networkStatus: null,
|
|
721
|
+
startTransactionTime: new Date().getTime(),
|
|
722
|
+
externalTransactionId: null,
|
|
723
|
+
executedTransactionId: null,
|
|
724
|
+
executedTransactionTime: null,
|
|
725
|
+
explorerUrl: null,
|
|
726
|
+
diagnosisUrl: null,
|
|
727
|
+
trackingCode: null,
|
|
728
|
+
internalSteps: null,
|
|
729
|
+
// transactions
|
|
730
|
+
evmTransaction: null,
|
|
731
|
+
evmApprovalTransaction: null,
|
|
732
|
+
starknetTransaction: null,
|
|
733
|
+
starknetApprovalTransaction: null,
|
|
734
|
+
tronTransaction: null,
|
|
735
|
+
tronApprovalTransaction: null,
|
|
736
|
+
cosmosTransaction: null,
|
|
737
|
+
solanaTransaction: null,
|
|
738
|
+
transferTransaction: null,
|
|
739
|
+
// front fields
|
|
740
|
+
hasAlreadyProceededToSign: false
|
|
741
|
+
};
|
|
742
|
+
})) || []
|
|
743
|
+
};
|
|
744
|
+
}
|
|
618
745
|
|
|
619
746
|
var SwapActionTypes;
|
|
620
747
|
(function (SwapActionTypes) {
|
|
@@ -662,7 +789,10 @@ function logRPCError(error, swap, currentStep, walletType) {
|
|
|
662
789
|
}
|
|
663
790
|
}
|
|
664
791
|
|
|
665
|
-
|
|
792
|
+
// this API key is limited and
|
|
793
|
+
// it is only for test purpose
|
|
794
|
+
var RANGO_PUBLIC_API_KEY = 'c6381a79-2817-4602-83bf-6a641a409e32';
|
|
795
|
+
var httpService = /*#__PURE__*/new rangoSdk.RangoClient(RANGO_DAPP_API_KEY || RANGO_PUBLIC_API_KEY, RANGO_DAPP_API_BASE_URL);
|
|
666
796
|
|
|
667
797
|
var swapClaimedBy = null;
|
|
668
798
|
/**
|
|
@@ -2773,6 +2903,7 @@ function useQueueManager(params) {
|
|
|
2773
2903
|
}
|
|
2774
2904
|
|
|
2775
2905
|
exports.PrettyError = PrettyError;
|
|
2906
|
+
exports.calculatePendingSwap = calculatePendingSwap;
|
|
2776
2907
|
exports.cancelSwap = cancelSwap;
|
|
2777
2908
|
exports.checkWaitingForNetworkChange = checkWaitingForNetworkChange;
|
|
2778
2909
|
exports.getCurrentBlockchainOfOrNull = getCurrentBlockchainOfOrNull;
|