@rango-dev/queue-manager-rango-preset 0.1.10-next.77 → 0.1.10-next.80

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.
Files changed (39) hide show
  1. package/dist/actions/checkStatus.d.ts.map +1 -1
  2. package/dist/actions/createTransaction.d.ts.map +1 -1
  3. package/dist/constants.d.ts +1 -3
  4. package/dist/constants.d.ts.map +1 -1
  5. package/dist/helpers.d.ts +2 -2
  6. package/dist/helpers.d.ts.map +1 -1
  7. package/dist/index.d.ts +2 -0
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/queue-manager-rango-preset.cjs.development.js +350 -294
  10. package/dist/queue-manager-rango-preset.cjs.development.js.map +1 -1
  11. package/dist/queue-manager-rango-preset.cjs.production.min.js +1 -1
  12. package/dist/queue-manager-rango-preset.cjs.production.min.js.map +1 -1
  13. package/dist/queue-manager-rango-preset.esm.js +345 -286
  14. package/dist/queue-manager-rango-preset.esm.js.map +1 -1
  15. package/dist/services/httpService.d.ts +3 -0
  16. package/dist/services/httpService.d.ts.map +1 -0
  17. package/dist/services/index.d.ts +2 -0
  18. package/dist/services/index.d.ts.map +1 -0
  19. package/dist/shared-errors.d.ts +1 -0
  20. package/dist/shared-errors.d.ts.map +1 -1
  21. package/dist/shared.d.ts +11 -16
  22. package/dist/shared.d.ts.map +1 -1
  23. package/dist/types.d.ts +3 -2
  24. package/dist/types.d.ts.map +1 -1
  25. package/package.json +4 -2
  26. package/src/actions/checkStatus.ts +14 -12
  27. package/src/actions/createTransaction.ts +21 -3
  28. package/src/constants.ts +1 -3
  29. package/src/helpers.ts +530 -192
  30. package/src/index.ts +3 -0
  31. package/src/services/httpService.ts +4 -0
  32. package/src/services/index.ts +1 -0
  33. package/src/shared-errors.ts +28 -1
  34. package/src/shared-sentry.ts +1 -1
  35. package/src/shared.ts +62 -35
  36. package/src/types.ts +2 -3
  37. package/dist/shared-api.d.ts +0 -10
  38. package/dist/shared-api.d.ts.map +0 -1
  39. package/src/shared-api.ts +0 -175
package/src/helpers.ts CHANGED
@@ -7,12 +7,9 @@ import {
7
7
  SwapStorage,
8
8
  } from './types';
9
9
  import {
10
- EvmBlockchainMeta,
11
10
  getBlockChainNameFromId,
12
11
  Meta,
13
12
  Network,
14
- Transaction,
15
- TransactionType,
16
13
  WalletState,
17
14
  WalletType,
18
15
  } from '@rango-dev/wallets-shared';
@@ -25,6 +22,9 @@ import {
25
22
  EvmTransaction,
26
23
  SolanaTransaction,
27
24
  Transfer as TransferTransaction,
25
+ Transaction,
26
+ TransactionType,
27
+ EvmBlockchainMeta,
28
28
  } from 'rango-sdk';
29
29
 
30
30
  import {
@@ -39,6 +39,8 @@ import {
39
39
  getCurrentBlockchainOf,
40
40
  getCurrentBlockchainOfOrNull,
41
41
  getEvmApproveUrl,
42
+ getStarknetApproveUrl,
43
+ getTronApproveUrl,
42
44
  getRelatedWalletOrNull,
43
45
  MessageSeverity,
44
46
  PendingSwap,
@@ -51,8 +53,8 @@ import {
51
53
  WalletTypeAndAddress,
52
54
  } from './shared';
53
55
  import { logRPCError } from './shared-sentry';
54
- import { PrettyError } from './shared-errors';
55
- import { mapAppErrorCodesToAPIErrorCode, reportFailed } from './shared-api';
56
+ import { PrettyError, mapAppErrorCodesToAPIErrorCode } from './shared-errors';
57
+ import { httpService } from './services';
56
58
 
57
59
  type WhenTaskBlocked = Parameters<NonNullable<SwapQueueDef['whenTaskBlocked']>>;
58
60
  type WhenTaskBlockedEvent = WhenTaskBlocked[0];
@@ -144,16 +146,18 @@ export function updateSwapStatus({
144
146
  details && details.includes('Warning')
145
147
  ? 'Swap canceled by user.'
146
148
  : details;
149
+ const walletType = getRelatedWalletOrNull(swap, currentStep!)?.walletType;
147
150
  swap.extraMessageSeverity = MessageSeverity.error;
148
- reportFailed(
149
- swap.requestId,
150
- currentStep?.id || 1,
151
- mapAppErrorCodesToAPIErrorCode(errorCode),
152
- errorReason || '',
153
- (currentStep
154
- ? getRelatedWalletOrNull(swap, currentStep)?.walletType
155
- : null) || null
156
- ).then();
151
+ httpService
152
+ .reportFailure({
153
+ requestId: swap.requestId,
154
+ step: currentStep?.id || 1,
155
+ eventType: mapAppErrorCodesToAPIErrorCode(errorCode),
156
+ reason: errorReason || '',
157
+ data: walletType ? { wallet: walletType } : undefined,
158
+ })
159
+ .then()
160
+ .catch();
157
161
  } else if (!!nextStepStatus && ['running'].includes(nextStepStatus))
158
162
  swap.extraMessageSeverity = MessageSeverity.info;
159
163
  else if (!!nextStepStatus && ['success', 'approved'].includes(nextStepStatus))
@@ -456,6 +460,8 @@ export async function isNetworkMatchedForTransaction(
456
460
  WalletType.COSMOSTATION,
457
461
  WalletType.CLOVER,
458
462
  WalletType.BRAVE,
463
+ WalletType.FRONTIER,
464
+ WalletType.KUCOIN,
459
465
  ].includes(sourceWallet.walletType)
460
466
  ) {
461
467
  const provider = getEvmProvider(providers, sourceWallet.walletType);
@@ -500,6 +506,10 @@ export const getCurrentAddressOf = (
500
506
  const result =
501
507
  swap.wallets[step.evmTransaction?.blockChain || ''] ||
502
508
  swap.wallets[step.evmApprovalTransaction?.blockChain || ''] ||
509
+ swap.wallets[step.tronTransaction?.blockChain || ''] ||
510
+ swap.wallets[step.tronApprovalTransaction?.blockChain || ''] ||
511
+ swap.wallets[step.starknetTransaction?.blockChain || ''] ||
512
+ swap.wallets[step.starknetApprovalTransaction?.blockChain || ''] ||
503
513
  swap.wallets[step.cosmosTransaction?.blockChain || ''] ||
504
514
  swap.wallets[step.solanaTransaction?.blockChain || ''] ||
505
515
  (step.transferTransaction?.fromWalletAddress
@@ -526,7 +536,7 @@ export function getRelatedWallet(
526
536
  const walletType = wallet?.walletType;
527
537
  if (walletType === WalletType.UNKNOWN || wallet === null)
528
538
  throw PrettyError.AssertionFailed(
529
- `Wallet for source ${blockchain} not passed to transfer: walletType: ${walletType}`
539
+ `Wallet for source ${blockchain} not passed: walletType: ${walletType}`
530
540
  );
531
541
  return wallet;
532
542
  }
@@ -538,6 +548,10 @@ export const isTxAlreadyCreated = (
538
548
  const result =
539
549
  swap.wallets[step.evmTransaction?.blockChain || ''] ||
540
550
  swap.wallets[step.evmApprovalTransaction?.blockChain || ''] ||
551
+ swap.wallets[step.tronTransaction?.blockChain || ''] ||
552
+ swap.wallets[step.tronApprovalTransaction?.blockChain || ''] ||
553
+ swap.wallets[step.starknetTransaction?.blockChain || ''] ||
554
+ swap.wallets[step.starknetApprovalTransaction?.blockChain || ''] ||
541
555
  swap.wallets[step.cosmosTransaction?.blockChain || ''] ||
542
556
  swap.wallets[step.solanaTransaction?.blockChain || ''] ||
543
557
  step.transferTransaction?.fromWalletAddress ||
@@ -762,9 +776,15 @@ export function singTransaction(
762
776
  cosmosTransaction,
763
777
  solanaTransaction,
764
778
  transferTransaction,
779
+ tronTransaction,
780
+ tronApprovalTransaction,
781
+ starknetTransaction,
782
+ starknetApprovalTransaction,
765
783
  } = currentStep;
766
784
  const sourceWallet = getRelatedWallet(swap, currentStep);
785
+ const walletAddress = getCurrentAddressOf(swap, currentStep);
767
786
  const walletSigners = getSigners(sourceWallet.walletType);
787
+
768
788
  const onFinish = () => {
769
789
  if (actions.context.resetClaimedBy) {
770
790
  actions.context.resetClaimedBy();
@@ -799,65 +819,243 @@ export function singTransaction(
799
819
  });
800
820
 
801
821
  // Execute transaction
802
- walletSigners.executeEvmTransaction(evmApprovalTransaction, meta).then(
803
- (hash) => {
804
- console.debug('transaction of approval minted successfully', hash);
805
- const approveUrl = getEvmApproveUrl(
806
- hash,
807
- getCurrentBlockchainOf(swap, currentStep),
808
- meta.evmBasedChains
809
- );
810
- currentStep.explorerUrl = [
811
- ...(currentStep.explorerUrl || []),
812
- {
813
- url: approveUrl,
814
- description: `approve`,
815
- },
816
- ];
817
-
818
- // `currentStep` has been mutated, let's update storage.
819
- setStorage({
820
- ...getStorage(),
821
- swapDetails: swap,
822
- });
823
- schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
824
- next();
825
- onFinish();
826
- },
822
+ walletSigners
823
+ .getSigner(TransactionType.EVM)
824
+ .signAndSendTx(evmApprovalTransaction, walletAddress, null)
825
+ .then(
826
+ (hash) => {
827
+ console.debug('transaction of approval minted successfully', hash);
828
+ const approveUrl = getEvmApproveUrl(
829
+ hash,
830
+ getCurrentBlockchainOf(swap, currentStep),
831
+ meta.evmBasedChains
832
+ );
833
+ currentStep.explorerUrl = [
834
+ ...(currentStep.explorerUrl || []),
835
+ {
836
+ url: approveUrl,
837
+ description: `approve`,
838
+ },
839
+ ];
827
840
 
828
- (error) => {
829
- if (swap.status === 'failed') return;
830
- console.debug('error in approving', error);
831
- const { extraMessage, extraMessageDetail, extraMessageErrorCode } =
832
- prettifyErrorMessage(error);
833
- if (
834
- error &&
835
- error?.root &&
836
- error?.root?.message &&
837
- error?.root?.code &&
838
- error?.root?.reason
839
- ) {
840
- logRPCError(error.root, swap, currentStep, sourceWallet?.walletType);
841
+ // `currentStep` has been mutated, let's update storage.
842
+ setStorage({
843
+ ...getStorage(),
844
+ swapDetails: swap,
845
+ });
846
+ schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
847
+ next();
848
+ onFinish();
849
+ },
850
+
851
+ (error) => {
852
+ if (swap.status === 'failed') return;
853
+ console.debug('error in approving', error);
854
+ const { extraMessage, extraMessageDetail, extraMessageErrorCode } =
855
+ prettifyErrorMessage(error);
856
+ if (
857
+ error &&
858
+ error?.root &&
859
+ error?.root?.message &&
860
+ error?.root?.code &&
861
+ error?.root?.reason
862
+ ) {
863
+ logRPCError(
864
+ error.root,
865
+ swap,
866
+ currentStep,
867
+ sourceWallet?.walletType
868
+ );
869
+ }
870
+
871
+ const updateResult = updateSwapStatus({
872
+ getStorage,
873
+ setStorage,
874
+ nextStatus: 'failed',
875
+ nextStepStatus: 'failed',
876
+ message: extraMessage,
877
+ details: extraMessageDetail,
878
+ errorCode: extraMessageErrorCode,
879
+ });
880
+ notifier({
881
+ eventType: 'contract_rejected',
882
+ ...updateResult,
883
+ });
884
+
885
+ failed();
886
+ onFinish();
841
887
  }
888
+ );
889
+ return;
890
+ } else if (!!tronApprovalTransaction) {
891
+ // Update swap status
892
+ const message = `waiting for approval of ${currentStep?.fromSymbol} coin ${
893
+ sourceWallet.walletType === WalletType.WALLET_CONNECT
894
+ ? 'on your mobile phone'
895
+ : ''
896
+ }`;
897
+ const updateResult = updateSwapStatus({
898
+ getStorage,
899
+ setStorage,
900
+ nextStepStatus: 'waitingForApproval',
901
+ message,
902
+ details:
903
+ 'Waiting for approve transaction to be mined and confirmed successfully',
904
+ });
905
+ notifier({
906
+ eventType: 'confirm_contract',
907
+ ...updateResult,
908
+ });
842
909
 
843
- const updateResult = updateSwapStatus({
844
- getStorage,
845
- setStorage,
846
- nextStatus: 'failed',
847
- nextStepStatus: 'failed',
848
- message: extraMessage,
849
- details: extraMessageDetail,
850
- errorCode: extraMessageErrorCode,
851
- });
852
- notifier({
853
- eventType: 'contract_rejected',
854
- ...updateResult,
855
- });
910
+ // Execute transaction
911
+ walletSigners
912
+ .getSigner(TransactionType.TRON)
913
+ .signAndSendTx(tronApprovalTransaction, walletAddress, null)
914
+ .then(
915
+ (hash) => {
916
+ console.debug('transaction of approval minted successfully', hash);
917
+ const approveUrl = getTronApproveUrl(hash);
918
+ currentStep.explorerUrl = [
919
+ ...(currentStep.explorerUrl || []),
920
+ {
921
+ url: approveUrl,
922
+ description: `approve`,
923
+ },
924
+ ];
856
925
 
857
- failed();
858
- onFinish();
859
- }
860
- );
926
+ // `currentStep` has been mutated, let's update storage.
927
+ setStorage({
928
+ ...getStorage(),
929
+ swapDetails: swap,
930
+ });
931
+ schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
932
+ next();
933
+ onFinish();
934
+ },
935
+
936
+ (error) => {
937
+ if (swap.status === 'failed') return;
938
+ console.debug('error in approving', error);
939
+ const { extraMessage, extraMessageDetail, extraMessageErrorCode } =
940
+ prettifyErrorMessage(error);
941
+ if (
942
+ error &&
943
+ error?.root &&
944
+ error?.root?.message &&
945
+ error?.root?.code &&
946
+ error?.root?.reason
947
+ ) {
948
+ logRPCError(
949
+ error.root,
950
+ swap,
951
+ currentStep,
952
+ sourceWallet?.walletType
953
+ );
954
+ }
955
+
956
+ const updateResult = updateSwapStatus({
957
+ getStorage,
958
+ setStorage,
959
+ nextStatus: 'failed',
960
+ nextStepStatus: 'failed',
961
+ message: extraMessage,
962
+ details: extraMessageDetail,
963
+ errorCode: extraMessageErrorCode,
964
+ });
965
+ notifier({
966
+ eventType: 'contract_rejected',
967
+ ...updateResult,
968
+ });
969
+
970
+ failed();
971
+ onFinish();
972
+ }
973
+ );
974
+ return;
975
+ } else if (!!starknetApprovalTransaction) {
976
+ // Update swap status
977
+ const message = `waiting for approval of ${currentStep?.fromSymbol} coin ${
978
+ sourceWallet.walletType === WalletType.WALLET_CONNECT
979
+ ? 'on your mobile phone'
980
+ : ''
981
+ }`;
982
+ const updateResult = updateSwapStatus({
983
+ getStorage,
984
+ setStorage,
985
+ nextStepStatus: 'waitingForApproval',
986
+ message,
987
+ details:
988
+ 'Waiting for approve transaction to be mined and confirmed successfully',
989
+ });
990
+ notifier({
991
+ eventType: 'confirm_contract',
992
+ ...updateResult,
993
+ });
994
+
995
+ // Execute transaction
996
+ walletSigners
997
+ .getSigner(TransactionType.STARKNET)
998
+ .signAndSendTx(starknetApprovalTransaction, walletAddress, null)
999
+ .then(
1000
+ (hash) => {
1001
+ console.debug('transaction of approval minted successfully', hash);
1002
+ const approveUrl = getStarknetApproveUrl(hash);
1003
+ currentStep.explorerUrl = [
1004
+ ...(currentStep.explorerUrl || []),
1005
+ {
1006
+ url: approveUrl,
1007
+ description: `approve`,
1008
+ },
1009
+ ];
1010
+
1011
+ // `currentStep` has been mutated, let's update storage.
1012
+ setStorage({
1013
+ ...getStorage(),
1014
+ swapDetails: swap,
1015
+ });
1016
+ schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
1017
+ next();
1018
+ onFinish();
1019
+ },
1020
+
1021
+ (error) => {
1022
+ if (swap.status === 'failed') return;
1023
+ console.debug('error in approving', error);
1024
+ const { extraMessage, extraMessageDetail, extraMessageErrorCode } =
1025
+ prettifyErrorMessage(error);
1026
+ if (
1027
+ error &&
1028
+ error?.root &&
1029
+ error?.root?.message &&
1030
+ error?.root?.code &&
1031
+ error?.root?.reason
1032
+ ) {
1033
+ logRPCError(
1034
+ error.root,
1035
+ swap,
1036
+ currentStep,
1037
+ sourceWallet?.walletType
1038
+ );
1039
+ }
1040
+
1041
+ const updateResult = updateSwapStatus({
1042
+ getStorage,
1043
+ setStorage,
1044
+ nextStatus: 'failed',
1045
+ nextStepStatus: 'failed',
1046
+ message: extraMessage,
1047
+ details: extraMessageDetail,
1048
+ errorCode: extraMessageErrorCode,
1049
+ });
1050
+ notifier({
1051
+ eventType: 'contract_rejected',
1052
+ ...updateResult,
1053
+ });
1054
+
1055
+ failed();
1056
+ onFinish();
1057
+ }
1058
+ );
861
1059
  return;
862
1060
  }
863
1061
 
@@ -881,34 +1079,37 @@ export function singTransaction(
881
1079
  ...updateResult,
882
1080
  });
883
1081
 
884
- walletSigners.executeTransfer(transferTransaction, meta).then(
885
- (txId) => {
886
- setStepTransactionIds(actions, txId, 'transfer_confirmed', notifier);
887
- schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
888
- next();
889
- onFinish();
890
- },
891
- (error) => {
892
- if (swap.status === 'failed') return;
893
- const { extraMessage, extraMessageDetail, extraMessageErrorCode } =
894
- prettifyErrorMessage(error);
895
- const updateResult = updateSwapStatus({
896
- getStorage,
897
- setStorage,
898
- nextStatus: 'failed',
899
- nextStepStatus: 'failed',
900
- message: extraMessage,
901
- details: extraMessageDetail,
902
- errorCode: extraMessageErrorCode,
903
- });
904
- notifier({
905
- eventType: 'transfer_rejected',
906
- ...updateResult,
907
- });
908
- failed();
909
- onFinish();
910
- }
911
- );
1082
+ walletSigners
1083
+ .getSigner(TransactionType.TRANSFER)
1084
+ .signAndSendTx(transferTransaction, walletAddress, null)
1085
+ .then(
1086
+ (txId) => {
1087
+ setStepTransactionIds(actions, txId, 'transfer_confirmed', notifier);
1088
+ schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
1089
+ next();
1090
+ onFinish();
1091
+ },
1092
+ (error) => {
1093
+ if (swap.status === 'failed') return;
1094
+ const { extraMessage, extraMessageDetail, extraMessageErrorCode } =
1095
+ prettifyErrorMessage(error);
1096
+ const updateResult = updateSwapStatus({
1097
+ getStorage,
1098
+ setStorage,
1099
+ nextStatus: 'failed',
1100
+ nextStepStatus: 'failed',
1101
+ message: extraMessage,
1102
+ details: extraMessageDetail,
1103
+ errorCode: extraMessageErrorCode,
1104
+ });
1105
+ notifier({
1106
+ eventType: 'transfer_rejected',
1107
+ ...updateResult,
1108
+ });
1109
+ failed();
1110
+ onFinish();
1111
+ }
1112
+ );
912
1113
  } else if (!!evmTransaction) {
913
1114
  const updateResult = updateSwapStatus({
914
1115
  getStorage,
@@ -922,44 +1123,52 @@ export function singTransaction(
922
1123
  ...updateResult,
923
1124
  });
924
1125
 
925
- walletSigners.executeEvmTransaction(evmTransaction, meta).then(
926
- (id) => {
927
- setStepTransactionIds(actions, id, 'smart_contract_called', notifier);
928
- schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
929
- next();
930
- onFinish();
931
- },
932
- (error) => {
933
- if (swap.status === 'failed') return;
934
- const { extraMessage, extraMessageDetail, extraMessageErrorCode } =
935
- prettifyErrorMessage(error);
936
- if (
937
- error &&
938
- error?.root &&
939
- error?.root?.message &&
940
- error?.root?.code &&
941
- error?.root?.reason
942
- ) {
943
- logRPCError(error.root, swap, currentStep, sourceWallet?.walletType);
944
- }
945
- const updateResult = updateSwapStatus({
946
- getStorage,
947
- setStorage,
948
- nextStatus: 'failed',
949
- nextStepStatus: 'failed',
950
- message: extraMessage,
951
- details: extraMessageDetail,
952
- errorCode: extraMessageErrorCode,
953
- });
954
- notifier({
955
- eventType: 'smart_contract_call_failed',
956
- ...updateResult,
957
- });
1126
+ walletSigners
1127
+ .getSigner(TransactionType.EVM)
1128
+ .signAndSendTx(evmTransaction, walletAddress, null)
1129
+ .then(
1130
+ (id) => {
1131
+ setStepTransactionIds(actions, id, 'smart_contract_called', notifier);
1132
+ schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
1133
+ next();
1134
+ onFinish();
1135
+ },
1136
+ (error) => {
1137
+ if (swap.status === 'failed') return;
1138
+ const { extraMessage, extraMessageDetail, extraMessageErrorCode } =
1139
+ prettifyErrorMessage(error);
1140
+ if (
1141
+ error &&
1142
+ error?.root &&
1143
+ error?.root?.message &&
1144
+ error?.root?.code &&
1145
+ error?.root?.reason
1146
+ ) {
1147
+ logRPCError(
1148
+ error.root,
1149
+ swap,
1150
+ currentStep,
1151
+ sourceWallet?.walletType
1152
+ );
1153
+ }
1154
+ const updateResult = updateSwapStatus({
1155
+ getStorage,
1156
+ setStorage,
1157
+ nextStatus: 'failed',
1158
+ nextStepStatus: 'failed',
1159
+ message: extraMessage,
1160
+ details: extraMessageDetail,
1161
+ errorCode: extraMessageErrorCode,
1162
+ });
1163
+ notifier({
1164
+ eventType: 'smart_contract_call_failed',
1165
+ ...updateResult,
1166
+ });
958
1167
 
959
- failed();
960
- onFinish();
961
- }
962
- );
1168
+ failed();
1169
+ onFinish();
1170
+ }
1171
+ );
963
1172
  } else if (!!cosmosTransaction) {
964
1173
  const updateResult = updateSwapStatus({
965
1174
  getStorage,
@@ -1005,35 +1214,38 @@ export function singTransaction(
1005
1214
  return;
1006
1215
  }
1007
1216
 
1008
- walletSigners.executeCosmosMessage(cosmosTransaction, meta).then(
1009
- // todo
1010
- (id: string | null) => {
1011
- setStepTransactionIds(actions, id, 'smart_contract_called', notifier);
1012
- schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
1013
- next();
1014
- onFinish();
1015
- },
1016
- (error: string | null) => {
1017
- if (swap.status === 'failed') return;
1018
- const { extraMessage, extraMessageDetail, extraMessageErrorCode } =
1019
- prettifyErrorMessage(error);
1020
- const updateResult = updateSwapStatus({
1021
- getStorage,
1022
- setStorage,
1023
- nextStatus: 'failed',
1024
- nextStepStatus: 'failed',
1025
- message: extraMessage,
1026
- details: extraMessageDetail,
1027
- errorCode: extraMessageErrorCode,
1028
- });
1029
- notifier({
1030
- eventType: 'smart_contract_call_failed',
1031
- ...updateResult,
1032
- });
1033
- failed();
1034
- onFinish();
1035
- }
1036
- );
1217
+ walletSigners
1218
+ .getSigner(TransactionType.COSMOS)
1219
+ .signAndSendTx(cosmosTransaction, walletAddress, null)
1220
+ .then(
1221
+ // todo
1222
+ (id: string | null) => {
1223
+ setStepTransactionIds(actions, id, 'smart_contract_called', notifier);
1224
+ schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
1225
+ next();
1226
+ onFinish();
1227
+ },
1228
+ (error: string | null) => {
1229
+ if (swap.status === 'failed') return;
1230
+ const { extraMessage, extraMessageDetail, extraMessageErrorCode } =
1231
+ prettifyErrorMessage(error);
1232
+ const updateResult = updateSwapStatus({
1233
+ getStorage,
1234
+ setStorage,
1235
+ nextStatus: 'failed',
1236
+ nextStepStatus: 'failed',
1237
+ message: extraMessage,
1238
+ details: extraMessageDetail,
1239
+ errorCode: extraMessageErrorCode,
1240
+ });
1241
+ notifier({
1242
+ eventType: 'smart_contract_call_failed',
1243
+ ...updateResult,
1244
+ });
1245
+ failed();
1246
+ onFinish();
1247
+ }
1248
+ );
1037
1249
  } else if (!!solanaTransaction) {
1038
1250
  const updateResult = updateSwapStatus({
1039
1251
  getStorage,
@@ -1048,34 +1260,160 @@ export function singTransaction(
1048
1260
  });
1049
1261
 
1050
1262
  const tx = solanaTransaction;
1051
- walletSigners.executeSolanaTransaction(tx, swap.requestId).then(
1052
- (txId) => {
1053
- setStepTransactionIds(actions, txId, 'smart_contract_called', notifier);
1054
- schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
1055
- next();
1056
- onFinish();
1057
- },
1058
- (error) => {
1059
- if (swap.status === 'failed') return;
1060
- const { extraMessage, extraMessageDetail, extraMessageErrorCode } =
1061
- prettifyErrorMessage(error);
1062
- const updateResult = updateSwapStatus({
1063
- getStorage,
1064
- setStorage,
1065
- nextStatus: 'failed',
1066
- nextStepStatus: 'failed',
1067
- message: extraMessage,
1068
- details: extraMessageDetail,
1069
- errorCode: extraMessageErrorCode,
1070
- });
1071
- notifier({
1072
- eventType: 'smart_contract_call_failed',
1073
- ...updateResult,
1074
- });
1075
- failed();
1076
- onFinish();
1077
- }
1078
- );
1263
+ walletSigners
1264
+ .getSigner(TransactionType.SOLANA)
1265
+ .signAndSendTx(tx, walletAddress, null)
1266
+ .then(
1267
+ (txId) => {
1268
+ setStepTransactionIds(
1269
+ actions,
1270
+ txId,
1271
+ 'smart_contract_called',
1272
+ notifier
1273
+ );
1274
+ schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
1275
+ next();
1276
+ onFinish();
1277
+ },
1278
+ (error) => {
1279
+ if (swap.status === 'failed') return;
1280
+ const { extraMessage, extraMessageDetail, extraMessageErrorCode } =
1281
+ prettifyErrorMessage(error);
1282
+ const updateResult = updateSwapStatus({
1283
+ getStorage,
1284
+ setStorage,
1285
+ nextStatus: 'failed',
1286
+ nextStepStatus: 'failed',
1287
+ message: extraMessage,
1288
+ details: extraMessageDetail,
1289
+ errorCode: extraMessageErrorCode,
1290
+ });
1291
+ notifier({
1292
+ eventType: 'smart_contract_call_failed',
1293
+ ...updateResult,
1294
+ });
1295
+ failed();
1296
+ onFinish();
1297
+ }
1298
+ );
1299
+ } else if (!!tronTransaction) {
1300
+ const updateResult = updateSwapStatus({
1301
+ getStorage,
1302
+ setStorage,
1303
+ nextStepStatus: 'running',
1304
+ message: executeMessage,
1305
+ details: executeDetails,
1306
+ });
1307
+ notifier({
1308
+ eventType: 'calling_smart_contract',
1309
+ ...updateResult,
1310
+ });
1311
+
1312
+ walletSigners
1313
+ .getSigner(TransactionType.TRON)
1314
+ .signAndSendTx(tronTransaction, walletAddress, null)
1315
+ .then(
1316
+ (id) => {
1317
+ setStepTransactionIds(actions, id, 'smart_contract_called', notifier);
1318
+ schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
1319
+ next();
1320
+ onFinish();
1321
+ },
1322
+ (error) => {
1323
+ if (swap.status === 'failed') return;
1324
+ const { extraMessage, extraMessageDetail, extraMessageErrorCode } =
1325
+ prettifyErrorMessage(error);
1326
+ if (
1327
+ error &&
1328
+ error?.root &&
1329
+ error?.root?.message &&
1330
+ error?.root?.code &&
1331
+ error?.root?.reason
1332
+ ) {
1333
+ logRPCError(
1334
+ error.root,
1335
+ swap,
1336
+ currentStep,
1337
+ sourceWallet?.walletType
1338
+ );
1339
+ }
1340
+ const updateResult = updateSwapStatus({
1341
+ getStorage,
1342
+ setStorage,
1343
+ nextStatus: 'failed',
1344
+ nextStepStatus: 'failed',
1345
+ message: extraMessage,
1346
+ details: extraMessageDetail,
1347
+ errorCode: extraMessageErrorCode,
1348
+ });
1349
+ notifier({
1350
+ eventType: 'smart_contract_call_failed',
1351
+ ...updateResult,
1352
+ });
1353
+
1354
+ failed();
1355
+ onFinish();
1356
+ }
1357
+ );
1358
+ } else if (!!starknetTransaction) {
1359
+ const updateResult = updateSwapStatus({
1360
+ getStorage,
1361
+ setStorage,
1362
+ nextStepStatus: 'running',
1363
+ message: executeMessage,
1364
+ details: executeDetails,
1365
+ });
1366
+ notifier({
1367
+ eventType: 'calling_smart_contract',
1368
+ ...updateResult,
1369
+ });
1370
+
1371
+ walletSigners
1372
+ .getSigner(TransactionType.STARKNET)
1373
+ .signAndSendTx(starknetTransaction, walletAddress, null)
1374
+ .then(
1375
+ (id) => {
1376
+ setStepTransactionIds(actions, id, 'smart_contract_called', notifier);
1377
+ schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
1378
+ next();
1379
+ onFinish();
1380
+ },
1381
+ (error) => {
1382
+ if (swap.status === 'failed') return;
1383
+ const { extraMessage, extraMessageDetail, extraMessageErrorCode } =
1384
+ prettifyErrorMessage(error);
1385
+ if (
1386
+ error &&
1387
+ error?.root &&
1388
+ error?.root?.message &&
1389
+ error?.root?.code &&
1390
+ error?.root?.reason
1391
+ ) {
1392
+ logRPCError(
1393
+ error.root,
1394
+ swap,
1395
+ currentStep,
1396
+ sourceWallet?.walletType
1397
+ );
1398
+ }
1399
+ const updateResult = updateSwapStatus({
1400
+ getStorage,
1401
+ setStorage,
1402
+ nextStatus: 'failed',
1403
+ nextStepStatus: 'failed',
1404
+ message: extraMessage,
1405
+ details: extraMessageDetail,
1406
+ errorCode: extraMessageErrorCode,
1407
+ });
1408
+ notifier({
1409
+ eventType: 'smart_contract_call_failed',
1410
+ ...updateResult,
1411
+ });
1412
+
1413
+ failed();
1414
+ onFinish();
1415
+ }
1416
+ );
1079
1417
  }
1080
1418
  }
1081
1419