@rango-dev/queue-manager-rango-preset 0.1.10-next.94 → 0.1.10-next.96

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rango-dev/queue-manager-rango-preset",
3
- "version": "0.1.10-next.94",
3
+ "version": "0.1.10-next.96",
4
4
  "license": "MIT",
5
5
  "module": "dist/queue-manager-rango-preset.esm.js",
6
6
  "main": "dist/index.js",
@@ -1,4 +1,5 @@
1
1
  import { ExecuterActions } from '@rango-dev/queue-manager-core';
2
+ import { Network } from '@rango-dev/wallets-shared';
2
3
  import {
3
4
  delay,
4
5
  getCurrentStep,
@@ -81,6 +82,7 @@ async function checkTransactionStatus({
81
82
  currentStep.starknetTransaction = null;
82
83
  currentStep.tronApprovalTransaction = null;
83
84
  currentStep.tronTransaction = null;
85
+ currentStep.fromBlockchain = newTransaction.blockChain as Network;
84
86
 
85
87
  if (isEvmTransaction(newTransaction)) {
86
88
  if (newTransaction.isApprovalTx)
@@ -57,9 +57,13 @@ export async function executeTransaction(
57
57
  const isWrongAddress = !isRequiredWalletConnected(swap, context.state);
58
58
  if (isWrongAddress) {
59
59
  const { type, address } = getRequiredWallet(swap);
60
- const description = !wallets
61
- ? ERROR_MESSAGE_WAIT_FOR_WALLET_DESCRIPTION(type)
62
- : ERROR_MESSAGE_WAIT_FOR_WALLET_DESCRIPTION_WRONG_WALLET(type, address);
60
+ const isWalletInCompatible = wallets?.blockchains?.find(
61
+ (w) => !w.accounts?.find((account) => account.walletType === type)
62
+ );
63
+ const description =
64
+ !wallets || isWalletInCompatible
65
+ ? ERROR_MESSAGE_WAIT_FOR_WALLET_DESCRIPTION(type)
66
+ : ERROR_MESSAGE_WAIT_FOR_WALLET_DESCRIPTION_WRONG_WALLET(type, address);
63
67
 
64
68
  const blockedFor = {
65
69
  reason: BlockReason.WAIT_FOR_CONNECT_WALLET,
package/src/helpers.ts CHANGED
@@ -87,6 +87,16 @@ function claimQueue() {
87
87
  };
88
88
  }
89
89
 
90
+ /**
91
+ *
92
+ * Returns "wallet and network" separately, even if the wallet is dashed inside.
93
+ *
94
+ */
95
+
96
+ function splitWalletNetwork(input: string): string[] {
97
+ return input?.split(/-(?=[^-]*$)/);
98
+ }
99
+
90
100
  /**
91
101
  *
92
102
  * Returns `steps`, if it's a `running` swap.
@@ -1107,7 +1117,10 @@ export function singTransaction(
1107
1117
  const notification = getSwapNotitfication('confirm_transfer', updateResult);
1108
1118
  notifier(notification);
1109
1119
 
1110
- if (notification.eventType !== 'transaction_expired') {
1120
+ if (notification.eventType === 'transaction_expired') {
1121
+ failed();
1122
+ onFinish();
1123
+ } else {
1111
1124
  walletSigners
1112
1125
  .getSigner(TransactionType.TRANSFER)
1113
1126
  .signAndSendTx(transferTransaction, walletAddress, null)
@@ -1161,7 +1174,10 @@ export function singTransaction(
1161
1174
  );
1162
1175
  notifier(notification);
1163
1176
 
1164
- if (notification.eventType !== 'transaction_expired') {
1177
+ if (notification.eventType === 'transaction_expired') {
1178
+ failed();
1179
+ onFinish();
1180
+ } else {
1165
1181
  walletSigners
1166
1182
  .getSigner(TransactionType.EVM)
1167
1183
  .signAndSendTx(evmTransaction, walletAddress, null)
@@ -1230,7 +1246,10 @@ export function singTransaction(
1230
1246
  );
1231
1247
  notifier(notification);
1232
1248
 
1233
- if (notification.eventType !== 'transaction_expired') {
1249
+ if (notification.eventType === 'transaction_expired') {
1250
+ failed();
1251
+ onFinish();
1252
+ } else {
1234
1253
  // If keplr wallet is executing contracts on terra, throw error. keplr doesn't support transfer or execute contracts. only IBC messages are supported
1235
1254
  if (
1236
1255
  (currentStep?.swapperId.toString() === 'TerraSwap' ||
@@ -1317,7 +1336,10 @@ export function singTransaction(
1317
1336
  );
1318
1337
  notifier(notification);
1319
1338
 
1320
- if (notification.eventType !== 'transaction_expired') {
1339
+ if (notification.eventType === 'transaction_expired') {
1340
+ failed();
1341
+ onFinish();
1342
+ } else {
1321
1343
  const tx = solanaTransaction;
1322
1344
  walletSigners
1323
1345
  .getSigner(TransactionType.SOLANA)
@@ -1360,120 +1382,146 @@ export function singTransaction(
1360
1382
  const updateResult = updateSwapStatus({
1361
1383
  getStorage,
1362
1384
  setStorage,
1363
- nextStepStatus: 'running',
1385
+ nextStepStatus: hasAlreadyProceededToSign ? 'failed' : 'running',
1386
+ nextStatus: hasAlreadyProceededToSign ? 'failed' : 'running',
1364
1387
  message: executeMessage,
1365
1388
  details: executeDetails,
1389
+ hasAlreadyProceededToSign,
1366
1390
  });
1367
- notifier({
1368
- eventType: 'calling_smart_contract',
1369
- ...updateResult,
1370
- });
1391
+ const notification = getSwapNotitfication(
1392
+ 'calling_smart_contract',
1393
+ updateResult
1394
+ );
1395
+ notifier(notification);
1371
1396
 
1372
- walletSigners
1373
- .getSigner(TransactionType.TRON)
1374
- .signAndSendTx(tronTransaction, walletAddress, null)
1375
- .then(
1376
- (id) => {
1377
- setStepTransactionIds(actions, id, 'smart_contract_called', notifier);
1378
- schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
1379
- next();
1380
- onFinish();
1381
- },
1382
- (error) => {
1383
- if (swap.status === 'failed') return;
1384
- const { extraMessage, extraMessageDetail, extraMessageErrorCode } =
1385
- prettifyErrorMessage(error);
1386
- if (
1387
- error &&
1388
- error?.root &&
1389
- error?.root?.message &&
1390
- error?.root?.code &&
1391
- error?.root?.reason
1392
- ) {
1393
- logRPCError(
1394
- error.root,
1395
- swap,
1396
- currentStep,
1397
- sourceWallet?.walletType
1397
+ if (notification.eventType === 'transaction_expired') {
1398
+ failed();
1399
+ onFinish();
1400
+ } else {
1401
+ walletSigners
1402
+ .getSigner(TransactionType.TRON)
1403
+ .signAndSendTx(tronTransaction, walletAddress, null)
1404
+ .then(
1405
+ (id) => {
1406
+ setStepTransactionIds(
1407
+ actions,
1408
+ id,
1409
+ 'smart_contract_called',
1410
+ notifier
1398
1411
  );
1399
- }
1400
- const updateResult = updateSwapStatus({
1401
- getStorage,
1402
- setStorage,
1403
- nextStatus: 'failed',
1404
- nextStepStatus: 'failed',
1405
- message: extraMessage,
1406
- details: extraMessageDetail,
1407
- errorCode: extraMessageErrorCode,
1408
- });
1409
- notifier({
1410
- eventType: 'smart_contract_call_failed',
1411
- ...updateResult,
1412
- });
1412
+ schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
1413
+ next();
1414
+ onFinish();
1415
+ },
1416
+ (error) => {
1417
+ if (swap.status === 'failed') return;
1418
+ const { extraMessage, extraMessageDetail, extraMessageErrorCode } =
1419
+ prettifyErrorMessage(error);
1420
+ if (
1421
+ error &&
1422
+ error?.root &&
1423
+ error?.root?.message &&
1424
+ error?.root?.code &&
1425
+ error?.root?.reason
1426
+ ) {
1427
+ logRPCError(
1428
+ error.root,
1429
+ swap,
1430
+ currentStep,
1431
+ sourceWallet?.walletType
1432
+ );
1433
+ }
1434
+ const updateResult = updateSwapStatus({
1435
+ getStorage,
1436
+ setStorage,
1437
+ nextStatus: 'failed',
1438
+ nextStepStatus: 'failed',
1439
+ message: extraMessage,
1440
+ details: extraMessageDetail,
1441
+ errorCode: extraMessageErrorCode,
1442
+ });
1443
+ notifier({
1444
+ eventType: 'smart_contract_call_failed',
1445
+ ...updateResult,
1446
+ });
1413
1447
 
1414
- failed();
1415
- onFinish();
1416
- }
1417
- );
1448
+ failed();
1449
+ onFinish();
1450
+ }
1451
+ );
1452
+ }
1418
1453
  } else if (!!starknetTransaction) {
1419
1454
  const updateResult = updateSwapStatus({
1420
1455
  getStorage,
1421
1456
  setStorage,
1422
- nextStepStatus: 'running',
1457
+ nextStepStatus: hasAlreadyProceededToSign ? 'failed' : 'running',
1458
+ nextStatus: hasAlreadyProceededToSign ? 'failed' : 'running',
1423
1459
  message: executeMessage,
1424
1460
  details: executeDetails,
1461
+ hasAlreadyProceededToSign,
1425
1462
  });
1426
- notifier({
1427
- eventType: 'calling_smart_contract',
1428
- ...updateResult,
1429
- });
1463
+ const notification = getSwapNotitfication(
1464
+ 'calling_smart_contract',
1465
+ updateResult
1466
+ );
1467
+ notifier(notification);
1430
1468
 
1431
- walletSigners
1432
- .getSigner(TransactionType.STARKNET)
1433
- .signAndSendTx(starknetTransaction, walletAddress, null)
1434
- .then(
1435
- (id) => {
1436
- setStepTransactionIds(actions, id, 'smart_contract_called', notifier);
1437
- schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
1438
- next();
1439
- onFinish();
1440
- },
1441
- (error) => {
1442
- if (swap.status === 'failed') return;
1443
- const { extraMessage, extraMessageDetail, extraMessageErrorCode } =
1444
- prettifyErrorMessage(error);
1445
- if (
1446
- error &&
1447
- error?.root &&
1448
- error?.root?.message &&
1449
- error?.root?.code &&
1450
- error?.root?.reason
1451
- ) {
1452
- logRPCError(
1453
- error.root,
1454
- swap,
1455
- currentStep,
1456
- sourceWallet?.walletType
1469
+ if (notification.eventType === 'transaction_expired') {
1470
+ failed();
1471
+ onFinish();
1472
+ } else {
1473
+ walletSigners
1474
+ .getSigner(TransactionType.STARKNET)
1475
+ .signAndSendTx(starknetTransaction, walletAddress, null)
1476
+ .then(
1477
+ (id) => {
1478
+ setStepTransactionIds(
1479
+ actions,
1480
+ id,
1481
+ 'smart_contract_called',
1482
+ notifier
1457
1483
  );
1458
- }
1459
- const updateResult = updateSwapStatus({
1460
- getStorage,
1461
- setStorage,
1462
- nextStatus: 'failed',
1463
- nextStepStatus: 'failed',
1464
- message: extraMessage,
1465
- details: extraMessageDetail,
1466
- errorCode: extraMessageErrorCode,
1467
- });
1468
- notifier({
1469
- eventType: 'smart_contract_call_failed',
1470
- ...updateResult,
1471
- });
1484
+ schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
1485
+ next();
1486
+ onFinish();
1487
+ },
1488
+ (error) => {
1489
+ if (swap.status === 'failed') return;
1490
+ const { extraMessage, extraMessageDetail, extraMessageErrorCode } =
1491
+ prettifyErrorMessage(error);
1492
+ if (
1493
+ error &&
1494
+ error?.root &&
1495
+ error?.root?.message &&
1496
+ error?.root?.code &&
1497
+ error?.root?.reason
1498
+ ) {
1499
+ logRPCError(
1500
+ error.root,
1501
+ swap,
1502
+ currentStep,
1503
+ sourceWallet?.walletType
1504
+ );
1505
+ }
1506
+ const updateResult = updateSwapStatus({
1507
+ getStorage,
1508
+ setStorage,
1509
+ nextStatus: 'failed',
1510
+ nextStepStatus: 'failed',
1511
+ message: extraMessage,
1512
+ details: extraMessageDetail,
1513
+ errorCode: extraMessageErrorCode,
1514
+ });
1515
+ notifier({
1516
+ eventType: 'smart_contract_call_failed',
1517
+ ...updateResult,
1518
+ });
1472
1519
 
1473
- failed();
1474
- onFinish();
1475
- }
1476
- );
1520
+ failed();
1521
+ onFinish();
1522
+ }
1523
+ );
1524
+ }
1477
1525
  }
1478
1526
  }
1479
1527
 
@@ -1483,8 +1531,7 @@ export function checkWaitingForConnectWalletChange(params: {
1483
1531
  evmChains: EvmBlockchainMeta[];
1484
1532
  }): void {
1485
1533
  const { wallet_network, evmChains, manager } = params;
1486
- const [wallet, network] = wallet_network.split('-');
1487
-
1534
+ const [wallet, network] = splitWalletNetwork(wallet_network);
1488
1535
  // We only need change network for EVM chains.
1489
1536
  if (!evmChains.some((chain) => chain.name == network)) return;
1490
1537
 
@@ -1509,7 +1556,11 @@ export function checkWaitingForConnectWalletChange(params: {
1509
1556
  }
1510
1557
  );
1511
1558
 
1512
- if (currentStepRequiredWallet === wallet && hasWaitingForConnect) {
1559
+ if (
1560
+ currentStepRequiredWallet === wallet &&
1561
+ hasWaitingForConnect &&
1562
+ getCurrentBlockchainOfOrNull(swap, currentStep) != network
1563
+ ) {
1513
1564
  const queueInstance = q.list;
1514
1565
  const { type } = getRequiredWallet(swap);
1515
1566
  const description = ERROR_MESSAGE_WAIT_FOR_CHANGE_NETWORK(type);
@@ -1582,7 +1633,7 @@ export function retryOn(
1582
1633
  manager?: Manager,
1583
1634
  options = { fallbackToOnlyWallet: true }
1584
1635
  ): void {
1585
- const [wallet, network] = wallet_network.split('-');
1636
+ const [wallet, network] = splitWalletNetwork(wallet_network);
1586
1637
  if (!wallet || !network) {
1587
1638
  return;
1588
1639
  }