@ledgerhq/live-common 34.54.0-nightly.20251206023719 → 34.54.0-nightly.20251209140356

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 (212) hide show
  1. package/lib/__tests__/test-helpers/environment.js +2 -0
  2. package/lib/__tests__/test-helpers/environment.js.map +1 -1
  3. package/lib/account/serialization.js +1 -1
  4. package/lib/account/serialization.js.map +1 -1
  5. package/lib/account/support.js +1 -1
  6. package/lib/account/support.js.map +1 -1
  7. package/lib/bridge/generic-alpaca/getAccountShape.d.ts.map +1 -1
  8. package/lib/bridge/generic-alpaca/getAccountShape.js +3 -2
  9. package/lib/bridge/generic-alpaca/getAccountShape.js.map +1 -1
  10. package/lib/bridge/generic-alpaca/prepareTransaction.d.ts.map +1 -1
  11. package/lib/bridge/generic-alpaca/prepareTransaction.js +7 -0
  12. package/lib/bridge/generic-alpaca/prepareTransaction.js.map +1 -1
  13. package/lib/domain/getTokensWithFunds.d.ts +7 -1
  14. package/lib/domain/getTokensWithFunds.d.ts.map +1 -1
  15. package/lib/domain/getTokensWithFunds.js +15 -4
  16. package/lib/domain/getTokensWithFunds.js.map +1 -1
  17. package/lib/domain/getTotalStakeableAssets.d.ts +10 -0
  18. package/lib/domain/getTotalStakeableAssets.d.ts.map +1 -0
  19. package/lib/domain/getTotalStakeableAssets.js +35 -0
  20. package/lib/domain/getTotalStakeableAssets.js.map +1 -0
  21. package/lib/e2e/index.d.ts +9 -0
  22. package/lib/e2e/index.d.ts.map +1 -1
  23. package/lib/exchange/swap/api/v5/fetchCurrencyFrom.js +1 -1
  24. package/lib/exchange/swap/api/v5/fetchCurrencyFrom.js.map +1 -1
  25. package/lib/exchange/swap/getIncompatibleCurrencyKeys.d.ts.map +1 -1
  26. package/lib/exchange/swap/getIncompatibleCurrencyKeys.js +4 -0
  27. package/lib/exchange/swap/getIncompatibleCurrencyKeys.js.map +1 -1
  28. package/lib/exchange/swap/transactionStrategies.d.ts +2 -1
  29. package/lib/exchange/swap/transactionStrategies.d.ts.map +1 -1
  30. package/lib/exchange/swap/transactionStrategies.js +7 -6
  31. package/lib/exchange/swap/transactionStrategies.js.map +1 -1
  32. package/lib/featureFlags/defaultFeatures.d.ts +2 -0
  33. package/lib/featureFlags/defaultFeatures.d.ts.map +1 -1
  34. package/lib/featureFlags/defaultFeatures.js +3 -0
  35. package/lib/featureFlags/defaultFeatures.js.map +1 -1
  36. package/lib/featureFlags/firebaseFeatureFlags.js +1 -1
  37. package/lib/featureFlags/firebaseFeatureFlags.js.map +1 -1
  38. package/lib/featureFlags/useFeature.d.ts +1 -1
  39. package/lib/featureFlags/useFeature.d.ts.map +1 -1
  40. package/lib/featureFlags/useHasOverriddenFeatureFlags.js +1 -1
  41. package/lib/featureFlags/useHasOverriddenFeatureFlags.js.map +1 -1
  42. package/lib/hw/getBitcoinLikeInfo.js +1 -1
  43. package/lib/hw/getBitcoinLikeInfo.js.map +1 -1
  44. package/lib/mock/account.js +1 -1
  45. package/lib/mock/account.js.map +1 -1
  46. package/lib/modularDrawer/hooks/useCurrenciesUnderFeatureFlag.d.ts.map +1 -1
  47. package/lib/modularDrawer/hooks/useCurrenciesUnderFeatureFlag.js +6 -0
  48. package/lib/modularDrawer/hooks/useCurrenciesUnderFeatureFlag.js.map +1 -1
  49. package/lib/wallet-api/Exchange/SwapError.d.ts +93 -0
  50. package/lib/wallet-api/Exchange/SwapError.d.ts.map +1 -0
  51. package/lib/wallet-api/Exchange/SwapError.js +142 -0
  52. package/lib/wallet-api/Exchange/SwapError.js.map +1 -0
  53. package/lib/wallet-api/Exchange/handleSwapErrors.d.ts +40 -0
  54. package/lib/wallet-api/Exchange/handleSwapErrors.d.ts.map +1 -0
  55. package/lib/wallet-api/Exchange/handleSwapErrors.js +112 -0
  56. package/lib/wallet-api/Exchange/handleSwapErrors.js.map +1 -0
  57. package/lib/wallet-api/Exchange/index.d.ts +4 -0
  58. package/lib/wallet-api/Exchange/index.d.ts.map +1 -0
  59. package/lib/wallet-api/Exchange/index.js +27 -0
  60. package/lib/wallet-api/Exchange/index.js.map +1 -0
  61. package/lib/wallet-api/Exchange/parser.d.ts +46 -0
  62. package/lib/wallet-api/Exchange/parser.d.ts.map +1 -0
  63. package/lib/wallet-api/Exchange/parser.js +97 -0
  64. package/lib/wallet-api/Exchange/parser.js.map +1 -0
  65. package/lib/wallet-api/Exchange/server.d.ts.map +1 -1
  66. package/lib/wallet-api/Exchange/server.js +226 -177
  67. package/lib/wallet-api/Exchange/server.js.map +1 -1
  68. package/lib/wallet-api/Exchange/tracking.d.ts +7 -6
  69. package/lib/wallet-api/Exchange/tracking.d.ts.map +1 -1
  70. package/lib/wallet-api/Exchange/tracking.js +52 -13
  71. package/lib/wallet-api/Exchange/tracking.js.map +1 -1
  72. package/lib/wallet-api/logic.d.ts +1 -1
  73. package/lib/wallet-api/logic.d.ts.map +1 -1
  74. package/lib/wallet-api/logic.js +5 -5
  75. package/lib/wallet-api/logic.js.map +1 -1
  76. package/lib/wallet-api/react.d.ts.map +1 -1
  77. package/lib/wallet-api/react.js +9 -6
  78. package/lib/wallet-api/react.js.map +1 -1
  79. package/lib/wallet-api/tracking.d.ts +5 -5
  80. package/lib/wallet-api/tracking.d.ts.map +1 -1
  81. package/lib/wallet-api/tracking.js +30 -10
  82. package/lib/wallet-api/tracking.js.map +1 -1
  83. package/lib/wallet-api/useDappLogic.d.ts.map +1 -1
  84. package/lib/wallet-api/useDappLogic.js +31 -20
  85. package/lib/wallet-api/useDappLogic.js.map +1 -1
  86. package/lib/wallet-api/utils/extractDappURLFromManifest.js +3 -3
  87. package/lib/wallet-api/utils/extractDappURLFromManifest.js.map +1 -1
  88. package/lib/wallet-api/utils/extractURLFromManifest.js +1 -1
  89. package/lib/wallet-api/utils/extractURLFromManifest.js.map +1 -1
  90. package/lib-es/__tests__/test-helpers/environment.js +2 -0
  91. package/lib-es/__tests__/test-helpers/environment.js.map +1 -1
  92. package/lib-es/account/serialization.js +1 -1
  93. package/lib-es/account/serialization.js.map +1 -1
  94. package/lib-es/account/support.js +1 -1
  95. package/lib-es/account/support.js.map +1 -1
  96. package/lib-es/bridge/generic-alpaca/getAccountShape.d.ts.map +1 -1
  97. package/lib-es/bridge/generic-alpaca/getAccountShape.js +3 -2
  98. package/lib-es/bridge/generic-alpaca/getAccountShape.js.map +1 -1
  99. package/lib-es/bridge/generic-alpaca/prepareTransaction.d.ts.map +1 -1
  100. package/lib-es/bridge/generic-alpaca/prepareTransaction.js +7 -0
  101. package/lib-es/bridge/generic-alpaca/prepareTransaction.js.map +1 -1
  102. package/lib-es/domain/getTokensWithFunds.d.ts +7 -1
  103. package/lib-es/domain/getTokensWithFunds.d.ts.map +1 -1
  104. package/lib-es/domain/getTokensWithFunds.js +13 -3
  105. package/lib-es/domain/getTokensWithFunds.js.map +1 -1
  106. package/lib-es/domain/getTotalStakeableAssets.d.ts +10 -0
  107. package/lib-es/domain/getTotalStakeableAssets.d.ts.map +1 -0
  108. package/lib-es/domain/getTotalStakeableAssets.js +31 -0
  109. package/lib-es/domain/getTotalStakeableAssets.js.map +1 -0
  110. package/lib-es/e2e/index.d.ts +9 -0
  111. package/lib-es/e2e/index.d.ts.map +1 -1
  112. package/lib-es/exchange/swap/api/v5/fetchCurrencyFrom.js +1 -1
  113. package/lib-es/exchange/swap/api/v5/fetchCurrencyFrom.js.map +1 -1
  114. package/lib-es/exchange/swap/getIncompatibleCurrencyKeys.d.ts.map +1 -1
  115. package/lib-es/exchange/swap/getIncompatibleCurrencyKeys.js +4 -0
  116. package/lib-es/exchange/swap/getIncompatibleCurrencyKeys.js.map +1 -1
  117. package/lib-es/exchange/swap/transactionStrategies.d.ts +2 -1
  118. package/lib-es/exchange/swap/transactionStrategies.d.ts.map +1 -1
  119. package/lib-es/exchange/swap/transactionStrategies.js +7 -6
  120. package/lib-es/exchange/swap/transactionStrategies.js.map +1 -1
  121. package/lib-es/featureFlags/defaultFeatures.d.ts +2 -0
  122. package/lib-es/featureFlags/defaultFeatures.d.ts.map +1 -1
  123. package/lib-es/featureFlags/defaultFeatures.js +3 -0
  124. package/lib-es/featureFlags/defaultFeatures.js.map +1 -1
  125. package/lib-es/featureFlags/firebaseFeatureFlags.js +1 -1
  126. package/lib-es/featureFlags/firebaseFeatureFlags.js.map +1 -1
  127. package/lib-es/featureFlags/useFeature.d.ts +1 -1
  128. package/lib-es/featureFlags/useFeature.d.ts.map +1 -1
  129. package/lib-es/featureFlags/useHasOverriddenFeatureFlags.js +1 -1
  130. package/lib-es/featureFlags/useHasOverriddenFeatureFlags.js.map +1 -1
  131. package/lib-es/hw/getBitcoinLikeInfo.js +1 -1
  132. package/lib-es/hw/getBitcoinLikeInfo.js.map +1 -1
  133. package/lib-es/mock/account.js +1 -1
  134. package/lib-es/mock/account.js.map +1 -1
  135. package/lib-es/modularDrawer/hooks/useCurrenciesUnderFeatureFlag.d.ts.map +1 -1
  136. package/lib-es/modularDrawer/hooks/useCurrenciesUnderFeatureFlag.js +6 -0
  137. package/lib-es/modularDrawer/hooks/useCurrenciesUnderFeatureFlag.js.map +1 -1
  138. package/lib-es/wallet-api/Exchange/SwapError.d.ts +93 -0
  139. package/lib-es/wallet-api/Exchange/SwapError.d.ts.map +1 -0
  140. package/lib-es/wallet-api/Exchange/SwapError.js +128 -0
  141. package/lib-es/wallet-api/Exchange/SwapError.js.map +1 -0
  142. package/lib-es/wallet-api/Exchange/handleSwapErrors.d.ts +40 -0
  143. package/lib-es/wallet-api/Exchange/handleSwapErrors.d.ts.map +1 -0
  144. package/lib-es/wallet-api/Exchange/handleSwapErrors.js +106 -0
  145. package/lib-es/wallet-api/Exchange/handleSwapErrors.js.map +1 -0
  146. package/lib-es/wallet-api/Exchange/index.d.ts +4 -0
  147. package/lib-es/wallet-api/Exchange/index.d.ts.map +1 -0
  148. package/lib-es/wallet-api/Exchange/index.js +7 -0
  149. package/lib-es/wallet-api/Exchange/index.js.map +1 -0
  150. package/lib-es/wallet-api/Exchange/parser.d.ts +46 -0
  151. package/lib-es/wallet-api/Exchange/parser.d.ts.map +1 -0
  152. package/lib-es/wallet-api/Exchange/parser.js +90 -0
  153. package/lib-es/wallet-api/Exchange/parser.js.map +1 -0
  154. package/lib-es/wallet-api/Exchange/server.d.ts.map +1 -1
  155. package/lib-es/wallet-api/Exchange/server.js +223 -177
  156. package/lib-es/wallet-api/Exchange/server.js.map +1 -1
  157. package/lib-es/wallet-api/Exchange/tracking.d.ts +7 -6
  158. package/lib-es/wallet-api/Exchange/tracking.d.ts.map +1 -1
  159. package/lib-es/wallet-api/Exchange/tracking.js +52 -13
  160. package/lib-es/wallet-api/Exchange/tracking.js.map +1 -1
  161. package/lib-es/wallet-api/logic.d.ts +1 -1
  162. package/lib-es/wallet-api/logic.d.ts.map +1 -1
  163. package/lib-es/wallet-api/logic.js +5 -5
  164. package/lib-es/wallet-api/logic.js.map +1 -1
  165. package/lib-es/wallet-api/react.d.ts.map +1 -1
  166. package/lib-es/wallet-api/react.js +9 -6
  167. package/lib-es/wallet-api/react.js.map +1 -1
  168. package/lib-es/wallet-api/tracking.d.ts +5 -5
  169. package/lib-es/wallet-api/tracking.d.ts.map +1 -1
  170. package/lib-es/wallet-api/tracking.js +30 -10
  171. package/lib-es/wallet-api/tracking.js.map +1 -1
  172. package/lib-es/wallet-api/useDappLogic.d.ts.map +1 -1
  173. package/lib-es/wallet-api/useDappLogic.js +31 -20
  174. package/lib-es/wallet-api/useDappLogic.js.map +1 -1
  175. package/lib-es/wallet-api/utils/extractDappURLFromManifest.js +3 -3
  176. package/lib-es/wallet-api/utils/extractDappURLFromManifest.js.map +1 -1
  177. package/lib-es/wallet-api/utils/extractURLFromManifest.js +1 -1
  178. package/lib-es/wallet-api/utils/extractURLFromManifest.js.map +1 -1
  179. package/package.json +73 -73
  180. package/src/__tests__/test-helpers/environment.ts +2 -0
  181. package/src/account/serialization.ts +1 -1
  182. package/src/account/support.ts +1 -1
  183. package/src/bridge/generic-alpaca/getAccountShape.ts +4 -2
  184. package/src/bridge/generic-alpaca/prepareTransaction.ts +7 -0
  185. package/src/bridge/generic-alpaca/tests/prepareTransaction.test.ts +42 -0
  186. package/src/domain/getTokensWithFunds.ts +18 -5
  187. package/src/domain/getTotalStakeableAssets.test.ts +267 -0
  188. package/src/domain/getTotalStakeableAssets.ts +47 -0
  189. package/src/exchange/swap/api/v5/fetchCurrencyFrom.ts +1 -1
  190. package/src/exchange/swap/getIncompatibleCurrencyKeys.ts +4 -0
  191. package/src/exchange/swap/transactionStrategies.ts +8 -7
  192. package/src/featureFlags/defaultFeatures.ts +3 -0
  193. package/src/featureFlags/firebaseFeatureFlags.ts +1 -1
  194. package/src/featureFlags/useHasOverriddenFeatureFlags.ts +1 -1
  195. package/src/hw/getBitcoinLikeInfo.ts +1 -1
  196. package/src/mock/account.ts +1 -1
  197. package/src/modularDrawer/hooks/useCurrenciesUnderFeatureFlag.ts +6 -0
  198. package/src/wallet-api/Exchange/SwapError.test.ts +126 -0
  199. package/src/wallet-api/Exchange/SwapError.ts +159 -0
  200. package/src/wallet-api/Exchange/handleSwapErrors.test.ts +46 -0
  201. package/src/wallet-api/Exchange/handleSwapErrors.ts +161 -0
  202. package/src/wallet-api/Exchange/index.ts +26 -0
  203. package/src/wallet-api/Exchange/parser.test.ts +86 -0
  204. package/src/wallet-api/Exchange/parser.ts +119 -0
  205. package/src/wallet-api/Exchange/server.ts +287 -235
  206. package/src/wallet-api/Exchange/tracking.ts +56 -13
  207. package/src/wallet-api/logic.ts +5 -4
  208. package/src/wallet-api/react.ts +10 -5
  209. package/src/wallet-api/tracking.ts +30 -10
  210. package/src/wallet-api/useDappLogic.ts +32 -20
  211. package/src/wallet-api/utils/extractDappURLFromManifest.ts +3 -3
  212. package/src/wallet-api/utils/extractURLFromManifest.ts +1 -1
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSwapCode = exports.isHandledError = exports.handleErrors = exports.CustomErrorType = exports.StepError = exports.createStepError = exports.CompleteExchangeError = exports.PayinExtraIdError = exports.UnknownAccountError = exports.ListCurrencyError = exports.ListAccountError = exports.NotEnoughFunds = exports.IgnoredSignatureStepError = exports.SignatureStepError = exports.PayloadStepError = exports.NonceStepError = exports.SwapError = void 0;
4
+ // Export all error classes
5
+ var SwapError_1 = require("./SwapError");
6
+ Object.defineProperty(exports, "SwapError", { enumerable: true, get: function () { return SwapError_1.SwapError; } });
7
+ Object.defineProperty(exports, "NonceStepError", { enumerable: true, get: function () { return SwapError_1.NonceStepError; } });
8
+ Object.defineProperty(exports, "PayloadStepError", { enumerable: true, get: function () { return SwapError_1.PayloadStepError; } });
9
+ Object.defineProperty(exports, "SignatureStepError", { enumerable: true, get: function () { return SwapError_1.SignatureStepError; } });
10
+ Object.defineProperty(exports, "IgnoredSignatureStepError", { enumerable: true, get: function () { return SwapError_1.IgnoredSignatureStepError; } });
11
+ Object.defineProperty(exports, "NotEnoughFunds", { enumerable: true, get: function () { return SwapError_1.NotEnoughFunds; } });
12
+ Object.defineProperty(exports, "ListAccountError", { enumerable: true, get: function () { return SwapError_1.ListAccountError; } });
13
+ Object.defineProperty(exports, "ListCurrencyError", { enumerable: true, get: function () { return SwapError_1.ListCurrencyError; } });
14
+ Object.defineProperty(exports, "UnknownAccountError", { enumerable: true, get: function () { return SwapError_1.UnknownAccountError; } });
15
+ Object.defineProperty(exports, "PayinExtraIdError", { enumerable: true, get: function () { return SwapError_1.PayinExtraIdError; } });
16
+ Object.defineProperty(exports, "CompleteExchangeError", { enumerable: true, get: function () { return SwapError_1.CompleteExchangeError; } });
17
+ // Export parser utilities
18
+ var parser_1 = require("./parser");
19
+ Object.defineProperty(exports, "createStepError", { enumerable: true, get: function () { return parser_1.createStepError; } });
20
+ Object.defineProperty(exports, "StepError", { enumerable: true, get: function () { return parser_1.StepError; } });
21
+ Object.defineProperty(exports, "CustomErrorType", { enumerable: true, get: function () { return parser_1.CustomErrorType; } });
22
+ // Export error handler
23
+ var handleSwapErrors_1 = require("./handleSwapErrors");
24
+ Object.defineProperty(exports, "handleErrors", { enumerable: true, get: function () { return handleSwapErrors_1.handleErrors; } });
25
+ Object.defineProperty(exports, "isHandledError", { enumerable: true, get: function () { return handleSwapErrors_1.isHandledError; } });
26
+ Object.defineProperty(exports, "getSwapCode", { enumerable: true, get: function () { return handleSwapErrors_1.getSwapCode; } });
27
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/wallet-api/Exchange/index.ts"],"names":[],"mappings":";;;AAAA,2BAA2B;AAC3B,yCAaqB;AAZnB,sGAAA,SAAS,OAAA;AACT,2GAAA,cAAc,OAAA;AACd,6GAAA,gBAAgB,OAAA;AAChB,+GAAA,kBAAkB,OAAA;AAClB,sHAAA,yBAAyB,OAAA;AACzB,2GAAA,cAAc,OAAA;AACd,6GAAA,gBAAgB,OAAA;AAChB,8GAAA,iBAAiB,OAAA;AACjB,gHAAA,mBAAmB,OAAA;AACnB,8GAAA,iBAAiB,OAAA;AACjB,kHAAA,qBAAqB,OAAA;AAIvB,0BAA0B;AAC1B,mCAAwF;AAA/E,yGAAA,eAAe,OAAA;AAAE,mGAAA,SAAS,OAAA;AAAE,yGAAA,eAAe,OAAA;AAEpD,uBAAuB;AACvB,uDAK4B;AAJ1B,gHAAA,YAAY,OAAA;AACZ,kHAAA,cAAc,OAAA;AACd,+GAAA,WAAW,OAAA"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Error Parser
3
+ * Routes errors to appropriate error classes based on step and context
4
+ */
5
+ /**
6
+ * Transaction step where error occurred
7
+ */
8
+ export declare enum StepError {
9
+ NONCE = "NonceStepError",
10
+ PAYLOAD = "PayloadStepError",
11
+ SIGNATURE = "SignatureStepError",
12
+ IGNORED_SIGNATURE = "IgnoredSignatureStepError",
13
+ CHECK_FUNDS = "CheckFundsStepError",
14
+ LIST_ACCOUNT = "ListAccountStepError",
15
+ LIST_CURRENCY = "ListCurrencyStepError",
16
+ UNKNOWN_ACCOUNT = "UnknownAccountStepError",
17
+ PAYIN_EXTRA_ID = "PayinExtraIdStepError"
18
+ }
19
+ /**
20
+ * Input for error parsing
21
+ */
22
+ export declare enum CustomErrorType {
23
+ SWAP = "swap"
24
+ }
25
+ export type ParseError = {
26
+ error: Error;
27
+ step?: StepError;
28
+ customErrorType?: CustomErrorType;
29
+ };
30
+ /**
31
+ * Creates a step-specific error by wrapping the original error
32
+ *
33
+ * @param error - Original error that occurred
34
+ * @param step - Step where error occurred (optional)
35
+ * @returns Wrapped error or original error if no step specified
36
+ */
37
+ export declare function createStepError({ error, step }: ParseError): Error;
38
+ /**
39
+ * Parses an error to determine the correct error class to return based on the context.
40
+ */
41
+ export declare function parseError({ error, step, customErrorType }: ParseError): Error;
42
+ export declare const hasMessage: (value: unknown) => value is {
43
+ message?: unknown;
44
+ };
45
+ export declare const toError: (value: unknown) => Error;
46
+ //# sourceMappingURL=parser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../../src/wallet-api/Exchange/parser.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAcH;;GAEG;AACH,oBAAY,SAAS;IACnB,KAAK,mBAAmB;IACxB,OAAO,qBAAqB;IAC5B,SAAS,uBAAuB;IAChC,iBAAiB,8BAA8B;IAC/C,WAAW,wBAAwB;IACnC,YAAY,yBAAyB;IACrC,aAAa,0BAA0B;IACvC,eAAe,4BAA4B;IAC3C,cAAc,0BAA0B;CACzC;AAED;;GAEG;AACH,oBAAY,eAAe;IACzB,IAAI,SAAS;CACd;AAED,MAAM,MAAM,UAAU,GAAG;IACvB,KAAK,EAAE,KAAK,CAAC;IACb,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,eAAe,CAAC,EAAE,eAAe,CAAC;CACnC,CAAC;AAiBF;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,UAAU,GAAG,KAAK,CAelE;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,eAAe,EAAE,EAAE,UAAU,GAAG,KAAK,CAM9E;AAED,eAAO,MAAM,UAAU,UAAW,OAAO;cAAwB,OAAO;CACL,CAAC;AAEpE,eAAO,MAAM,OAAO,UAAW,OAAO,KAAG,KAoBxC,CAAC"}
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ /**
3
+ * Error Parser
4
+ * Routes errors to appropriate error classes based on step and context
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.toError = exports.hasMessage = exports.parseError = exports.createStepError = exports.CustomErrorType = exports.StepError = void 0;
8
+ const SwapError_1 = require("./SwapError");
9
+ /**
10
+ * Transaction step where error occurred
11
+ */
12
+ var StepError;
13
+ (function (StepError) {
14
+ StepError["NONCE"] = "NonceStepError";
15
+ StepError["PAYLOAD"] = "PayloadStepError";
16
+ StepError["SIGNATURE"] = "SignatureStepError";
17
+ StepError["IGNORED_SIGNATURE"] = "IgnoredSignatureStepError";
18
+ StepError["CHECK_FUNDS"] = "CheckFundsStepError";
19
+ StepError["LIST_ACCOUNT"] = "ListAccountStepError";
20
+ StepError["LIST_CURRENCY"] = "ListCurrencyStepError";
21
+ StepError["UNKNOWN_ACCOUNT"] = "UnknownAccountStepError";
22
+ StepError["PAYIN_EXTRA_ID"] = "PayinExtraIdStepError";
23
+ })(StepError || (exports.StepError = StepError = {}));
24
+ /**
25
+ * Input for error parsing
26
+ */
27
+ var CustomErrorType;
28
+ (function (CustomErrorType) {
29
+ CustomErrorType["SWAP"] = "swap";
30
+ })(CustomErrorType || (exports.CustomErrorType = CustomErrorType = {}));
31
+ /**
32
+ * Maps step errors to error constructors
33
+ */
34
+ const ErrorMap = {
35
+ [StepError.NONCE]: SwapError_1.NonceStepError,
36
+ [StepError.PAYLOAD]: SwapError_1.PayloadStepError,
37
+ [StepError.SIGNATURE]: SwapError_1.SignatureStepError,
38
+ [StepError.IGNORED_SIGNATURE]: SwapError_1.IgnoredSignatureStepError,
39
+ [StepError.CHECK_FUNDS]: SwapError_1.NotEnoughFunds,
40
+ [StepError.LIST_ACCOUNT]: SwapError_1.ListAccountError,
41
+ [StepError.LIST_CURRENCY]: SwapError_1.ListCurrencyError,
42
+ [StepError.UNKNOWN_ACCOUNT]: SwapError_1.UnknownAccountError,
43
+ [StepError.PAYIN_EXTRA_ID]: SwapError_1.PayinExtraIdError,
44
+ };
45
+ /**
46
+ * Creates a step-specific error by wrapping the original error
47
+ *
48
+ * @param error - Original error that occurred
49
+ * @param step - Step where error occurred (optional)
50
+ * @returns Wrapped error or original error if no step specified
51
+ */
52
+ function createStepError({ error, step }) {
53
+ // If no step specified, return original error
54
+ if (!step) {
55
+ return error;
56
+ }
57
+ // Get error constructor for this step
58
+ const ErrorConstructor = ErrorMap[step];
59
+ if (!ErrorConstructor) {
60
+ return error;
61
+ }
62
+ // Wrap original error in step-specific error class
63
+ return new ErrorConstructor(error);
64
+ }
65
+ exports.createStepError = createStepError;
66
+ /**
67
+ * Parses an error to determine the correct error class to return based on the context.
68
+ */
69
+ function parseError({ error, step, customErrorType }) {
70
+ if (!step || customErrorType !== CustomErrorType.SWAP) {
71
+ return error;
72
+ }
73
+ return createStepError({ error, step });
74
+ }
75
+ exports.parseError = parseError;
76
+ const hasMessage = (value) => Boolean(value && typeof value === "object" && "message" in value);
77
+ exports.hasMessage = hasMessage;
78
+ const toError = (value) => {
79
+ if (value instanceof Error) {
80
+ return value;
81
+ }
82
+ if ((0, exports.hasMessage)(value) && typeof value.message === "string") {
83
+ return new Error(value.message);
84
+ }
85
+ return new Error(typeof value === "string"
86
+ ? value
87
+ : (() => {
88
+ try {
89
+ return JSON.stringify(value);
90
+ }
91
+ catch {
92
+ return String(value);
93
+ }
94
+ })());
95
+ };
96
+ exports.toError = toError;
97
+ //# sourceMappingURL=parser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parser.js","sourceRoot":"","sources":["../../../src/wallet-api/Exchange/parser.ts"],"names":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ACZ,CAAC;AAEF,eAAO,MAAM,QAAQ;cAYT,WAAW,EAAE;cACb,WAAW;cACX,WAAW;aACZ,eAAe;;;;;;;CAugBM,CAAC"}
@@ -1,4 +1,7 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.handlers = exports.ExchangeType = void 0;
4
7
  /* eslint-disable no-console */
@@ -20,6 +23,9 @@ const error_2 = require("../../exchange/error");
20
23
  const swap_1 = require("../../exchange/swap");
21
24
  const setBroadcastTransaction_1 = require("../../exchange/swap/setBroadcastTransaction");
22
25
  const hw_app_eth_1 = require("@ledgerhq/hw-app-eth");
26
+ const parser_1 = require("./parser");
27
+ const handleSwapErrors_1 = require("./handleSwapErrors");
28
+ const get_1 = __importDefault(require("lodash/get"));
23
29
  const handlers = ({ accounts, tracking, manifest, uiHooks: { "custom.exchange.start": uiExchangeStart, "custom.exchange.complete": uiExchangeComplete, "custom.exchange.error": uiError, "custom.isReady": uiIsReady, "custom.exchange.swap": uiSwap, }, }) => ({
24
30
  "custom.exchange.start": (0, wallet_api_server_1.customWrapper)(async (params) => {
25
31
  if (!params) {
@@ -198,175 +204,219 @@ const handlers = ({ accounts, tracking, manifest, uiHooks: { "custom.exchange.st
198
204
  }));
199
205
  }),
200
206
  "custom.exchange.swap": (0, wallet_api_server_1.customWrapper)(async (params) => {
201
- if (!params) {
202
- tracking.startExchangeNoParams(manifest);
203
- throw new wallet_api_core_1.ServerError((0, wallet_api_core_1.createUnknownError)({ message: "params is undefined" }));
204
- }
205
- const { provider, fromAmount, fromAmountAtomic, quoteId, toNewTokenId, customFeeConfig, swapAppVersion, sponsored, } = params;
206
- const trackingParams = {
207
- provider: params.provider,
208
- exchangeType: params.exchangeType,
209
- };
210
- tracking.startExchangeRequested(trackingParams);
211
- const exchangeStartParams = (await extractSwapStartParam(params, accounts));
212
- const { fromCurrency, fromAccount, fromParentAccount, toCurrency, toAccount, toParentAccount, } = exchangeStartParams.exchange;
213
- if (!fromAccount || !fromCurrency) {
214
- throw new wallet_api_core_1.ServerError((0, wallet_api_core_1.createAccountNotFound)(params.fromAccountId));
215
- }
216
- const fromAccountAddress = fromParentAccount
217
- ? fromParentAccount.freshAddress
218
- : fromAccount.freshAddress;
219
- const toAccountAddress = toParentAccount
220
- ? toParentAccount.freshAddress
221
- : toAccount.freshAddress;
222
- // Step 1: Open the drawer and open exchange app
223
- const startExchange = async () => {
224
- return new Promise((resolve, reject) => {
225
- uiExchangeStart({
226
- exchangeParams: exchangeStartParams,
227
- onSuccess: (nonce, device) => {
228
- tracking.startExchangeSuccess(trackingParams);
229
- resolve({ transactionId: nonce, device });
230
- },
231
- onCancel: error => {
232
- tracking.startExchangeFail(trackingParams);
233
- reject(error);
234
- },
207
+ try {
208
+ if (!params) {
209
+ tracking.startExchangeNoParams(manifest);
210
+ throw new wallet_api_core_1.ServerError((0, wallet_api_core_1.createUnknownError)({ message: "params is undefined" }));
211
+ }
212
+ const { provider, fromAmount, fromAmountAtomic, quoteId, toNewTokenId, customFeeConfig, swapAppVersion, sponsored, isEmbedded, } = params;
213
+ const trackingParams = {
214
+ provider: params.provider,
215
+ exchangeType: params.exchangeType,
216
+ isEmbeddedSwap: isEmbedded,
217
+ };
218
+ tracking.startExchangeRequested(trackingParams);
219
+ const exchangeStartParams = (await extractSwapStartParam(params, accounts));
220
+ const { fromCurrency, fromAccount, fromParentAccount, toCurrency, toAccount, toParentAccount, } = exchangeStartParams.exchange;
221
+ if (!fromAccount || !fromCurrency) {
222
+ throw new wallet_api_core_1.ServerError((0, wallet_api_core_1.createAccountNotFound)(params.fromAccountId));
223
+ }
224
+ const fromAccountAddress = fromParentAccount
225
+ ? fromParentAccount.freshAddress
226
+ : fromAccount.freshAddress;
227
+ const toAccountAddress = toParentAccount
228
+ ? toParentAccount.freshAddress
229
+ : toAccount.freshAddress;
230
+ // Step 1: Open the drawer and open exchange app
231
+ const startExchange = async () => {
232
+ return new Promise((resolve, reject) => {
233
+ uiExchangeStart({
234
+ exchangeParams: exchangeStartParams,
235
+ onSuccess: (nonce, device) => {
236
+ tracking.startExchangeSuccess(trackingParams);
237
+ resolve({ transactionId: nonce, device });
238
+ },
239
+ onCancel: error => {
240
+ tracking.startExchangeFail(trackingParams);
241
+ reject(error);
242
+ },
243
+ });
235
244
  });
245
+ };
246
+ let transactionId;
247
+ let deviceInfo;
248
+ try {
249
+ const result = await startExchange();
250
+ transactionId = result.transactionId;
251
+ deviceInfo = result.device;
252
+ }
253
+ catch (error) {
254
+ const rawError = (0, get_1.default)(error, "response.data.error", error);
255
+ const wrappedError = (0, parser_1.createStepError)({
256
+ error: (0, parser_1.toError)(rawError),
257
+ step: parser_1.StepError.NONCE,
258
+ });
259
+ throw wrappedError;
260
+ }
261
+ const { binaryPayload, signature, payinAddress, swapId, payinExtraId, extraTransactionParameters, } = await (0, actions_1.retrieveSwapPayload)({
262
+ provider,
263
+ deviceTransactionId: transactionId,
264
+ fromAccountAddress,
265
+ toAccountAddress,
266
+ fromAccountCurrency: fromCurrency.id,
267
+ toAccountCurrency: toCurrency.id,
268
+ amount: fromAmount,
269
+ amountInAtomicUnit: fromAmountAtomic,
270
+ quoteId,
271
+ toNewTokenId,
272
+ }).catch((error) => {
273
+ const wrappedError = (0, parser_1.createStepError)({
274
+ error: (0, get_1.default)(error, "response.data.error", error),
275
+ step: parser_1.StepError.PAYLOAD,
276
+ });
277
+ throw wrappedError;
236
278
  });
237
- };
238
- const { transactionId, device: deviceInfo } = await startExchange();
239
- const { binaryPayload, signature, payinAddress, swapId, payinExtraId, extraTransactionParameters, } = await (0, actions_1.retrieveSwapPayload)({
240
- provider,
241
- deviceTransactionId: transactionId,
242
- fromAccountAddress,
243
- toAccountAddress,
244
- fromAccountCurrency: fromCurrency.id,
245
- toAccountCurrency: toCurrency.id,
246
- amount: fromAmount,
247
- amountInAtomicUnit: fromAmountAtomic,
248
- quoteId,
249
- toNewTokenId,
250
- }).catch((error) => {
251
- throw error;
252
- });
253
- // Complete Swap
254
- const trackingCompleteParams = {
255
- provider: params.provider,
256
- exchangeType: params.exchangeType,
257
- };
258
- tracking.completeExchangeRequested(trackingCompleteParams);
259
- const strategyData = {
260
- recipient: payinAddress,
261
- amount: fromAmountAtomic,
262
- currency: fromCurrency,
263
- customFeeConfig: customFeeConfig ?? {},
264
- payinExtraId,
265
- extraTransactionParameters,
266
- sponsored,
267
- };
268
- const transaction = await getStrategy(strategyData, "swap").catch(async (error) => {
269
- throw error;
270
- });
271
- const mainFromAccount = (0, index_1.getMainAccount)(fromAccount, fromParentAccount);
272
- if (transaction.family !== mainFromAccount.currency.family) {
273
- return Promise.reject(new Error(`Account and transaction must be from the same family. Account family: ${mainFromAccount.currency.family}, Transaction family: ${transaction.family}`));
274
- }
275
- const accountBridge = (0, bridge_1.getAccountBridge)(fromAccount, fromParentAccount);
276
- /**
277
- * 'subAccountId' is used for ETH and it's ERC-20 tokens.
278
- * This field is ignored for BTC
279
- */
280
- const subAccountId = fromParentAccount && fromParentAccount.id !== fromAccount.id ? fromAccount.id : undefined;
281
- const bridgeTx = accountBridge.createTransaction(fromAccount);
282
- /**
283
- * We append the `recipient` to the tx created from `createTransaction`
284
- * to avoid having userGasLimit reset to null for ETH txs
285
- * cf. libs/ledger-live-common/src/families/ethereum/updateTransaction.ts
286
- */
287
- const tx = accountBridge.updateTransaction({
288
- ...bridgeTx,
289
- recipient: transaction.recipient,
290
- }, {
291
- ...transaction,
292
- feesStrategy: params.feeStrategy.toLowerCase(),
293
- subAccountId,
294
- });
295
- // Get amountExpectedTo and magnitudeAwareRate from binary payload
296
- const decodePayload = await (0, hw_app_exchange_1.decodeSwapPayload)(binaryPayload);
297
- const amountExpectedTo = new bignumber_js_1.BigNumber(decodePayload.amountToWallet.toString());
298
- const magnitudeAwareRate = tx.amount && amountExpectedTo.dividedBy(tx.amount);
299
- const refundAddress = decodePayload.refundAddress;
300
- const payoutAddress = decodePayload.payoutAddress;
301
- // tx.amount should be BigNumber
302
- tx.amount = new bignumber_js_1.BigNumber(tx.amount);
303
- return new Promise((resolve, reject) => uiSwap({
304
- exchangeParams: {
305
- exchangeType: wallet_api_exchange_module_1.ExchangeType.SWAP,
279
+ // Complete Swap
280
+ const trackingCompleteParams = {
306
281
  provider: params.provider,
307
- transaction: tx,
308
- signature: signature,
309
- binaryPayload: binaryPayload,
310
- exchange: {
311
- fromAccount,
312
- fromParentAccount,
313
- toAccount,
314
- toParentAccount,
315
- fromCurrency: fromCurrency,
316
- toCurrency: toCurrency,
317
- },
318
- feesStrategy: params.feeStrategy,
319
- swapId: swapId,
320
- amountExpectedTo: amountExpectedTo.toNumber(),
321
- magnitudeAwareRate,
322
- refundAddress,
323
- payoutAddress,
282
+ exchangeType: params.exchangeType,
283
+ isEmbeddedSwap: isEmbedded,
284
+ };
285
+ tracking.completeExchangeRequested(trackingCompleteParams);
286
+ const strategyData = {
287
+ recipient: payinAddress,
288
+ amount: fromAmountAtomic,
289
+ currency: fromCurrency,
290
+ customFeeConfig: customFeeConfig ?? {},
291
+ payinExtraId,
292
+ extraTransactionParameters,
324
293
  sponsored,
325
- },
326
- onSuccess: ({ operationHash, swapId }) => {
327
- tracking.completeExchangeSuccess({
328
- ...trackingParams,
329
- currency: transaction.family,
330
- });
331
- (0, setBroadcastTransaction_1.setBroadcastTransaction)({
332
- provider,
333
- result: { operation: operationHash, swapId },
334
- sourceCurrencyId: fromCurrency.id,
335
- targetCurrencyId: toCurrency?.id,
336
- hardwareWalletType: deviceInfo?.modelId,
337
- swapAppVersion,
338
- fromAccountAddress,
339
- toAccountAddress,
340
- fromAmount,
341
- });
342
- resolve({ operationHash, swapId });
343
- },
344
- onCancel: error => {
345
- (0, swap_1.postSwapCancelled)({
346
- provider: provider,
294
+ };
295
+ const transaction = await getStrategy(strategyData, "swap");
296
+ const mainFromAccount = (0, index_1.getMainAccount)(fromAccount, fromParentAccount);
297
+ if (transaction.family !== mainFromAccount.currency.family) {
298
+ return Promise.reject(new Error(`Account and transaction must be from the same family. Account family: ${mainFromAccount.currency.family}, Transaction family: ${transaction.family}`));
299
+ }
300
+ const accountBridge = (0, bridge_1.getAccountBridge)(fromAccount, fromParentAccount);
301
+ /**
302
+ * 'subAccountId' is used for ETH and it's ERC-20 tokens.
303
+ * This field is ignored for BTC
304
+ */
305
+ const subAccountId = fromParentAccount && fromParentAccount.id !== fromAccount.id ? fromAccount.id : undefined;
306
+ const bridgeTx = accountBridge.createTransaction(fromAccount);
307
+ /**
308
+ * We append the `recipient` to the tx created from `createTransaction`
309
+ * to avoid having userGasLimit reset to null for ETH txs
310
+ * cf. libs/ledger-live-common/src/families/ethereum/updateTransaction.ts
311
+ */
312
+ const tx = accountBridge.updateTransaction({
313
+ ...bridgeTx,
314
+ recipient: transaction.recipient,
315
+ }, {
316
+ ...transaction,
317
+ feesStrategy: params.feeStrategy.toLowerCase(),
318
+ subAccountId,
319
+ });
320
+ // Get amountExpectedTo and magnitudeAwareRate from binary payload
321
+ const decodePayload = await (0, hw_app_exchange_1.decodeSwapPayload)(binaryPayload);
322
+ const amountExpectedTo = new bignumber_js_1.BigNumber(decodePayload.amountToWallet.toString());
323
+ const magnitudeAwareRate = tx.amount && amountExpectedTo.dividedBy(tx.amount);
324
+ const refundAddress = decodePayload.refundAddress;
325
+ const payoutAddress = decodePayload.payoutAddress;
326
+ // tx.amount should be BigNumber
327
+ tx.amount = new bignumber_js_1.BigNumber(tx.amount);
328
+ return new Promise((resolve, reject) => uiSwap({
329
+ exchangeParams: {
330
+ exchangeType: wallet_api_exchange_module_1.ExchangeType.SWAP,
331
+ provider: params.provider,
332
+ transaction: tx,
333
+ signature: signature,
334
+ binaryPayload: binaryPayload,
335
+ exchange: {
336
+ fromAccount,
337
+ fromParentAccount,
338
+ toAccount,
339
+ toParentAccount,
340
+ fromCurrency: fromCurrency,
341
+ toCurrency: toCurrency,
342
+ },
343
+ feesStrategy: params.feeStrategy,
347
344
  swapId: swapId,
348
- swapStep: (0, error_2.getSwapStepFromError)(error),
349
- statusCode: error.name,
350
- errorMessage: error.message,
351
- sourceCurrencyId: fromCurrency.id,
352
- targetCurrencyId: toCurrency?.id,
353
- hardwareWalletType: deviceInfo?.modelId,
354
- swapType: quoteId ? "fixed" : "float",
355
- swapAppVersion,
356
- fromAccountAddress,
357
- toAccountAddress,
345
+ amountExpectedTo: amountExpectedTo.toNumber(),
346
+ magnitudeAwareRate,
358
347
  refundAddress,
359
348
  payoutAddress,
360
- fromAmount,
361
- seedIdFrom: mainFromAccount.seedIdentifier,
362
- seedIdTo: toParentAccount?.seedIdentifier || toAccount?.seedIdentifier,
363
- data: transaction.data
364
- ? `0x${(0, hw_app_eth_1.padHexString)(transaction.data?.toString("hex") || "")}`
365
- : "0x",
349
+ sponsored,
350
+ },
351
+ onSuccess: ({ operationHash, swapId }) => {
352
+ tracking.completeExchangeSuccess({
353
+ ...trackingParams,
354
+ currency: transaction.family,
355
+ });
356
+ (0, setBroadcastTransaction_1.setBroadcastTransaction)({
357
+ provider,
358
+ result: { operation: operationHash, swapId },
359
+ sourceCurrencyId: fromCurrency.id,
360
+ targetCurrencyId: toCurrency?.id,
361
+ hardwareWalletType: deviceInfo?.modelId,
362
+ swapAppVersion,
363
+ fromAccountAddress,
364
+ toAccountAddress,
365
+ fromAmount,
366
+ });
367
+ resolve({ operationHash, swapId });
368
+ },
369
+ onCancel: error => {
370
+ (0, swap_1.postSwapCancelled)({
371
+ provider: provider,
372
+ swapId: swapId,
373
+ swapStep: (0, error_2.getSwapStepFromError)(error),
374
+ statusCode: error.name,
375
+ errorMessage: error.message,
376
+ sourceCurrencyId: fromCurrency.id,
377
+ targetCurrencyId: toCurrency?.id,
378
+ hardwareWalletType: deviceInfo?.modelId,
379
+ swapType: quoteId ? "fixed" : "float",
380
+ swapAppVersion,
381
+ fromAccountAddress,
382
+ toAccountAddress,
383
+ refundAddress,
384
+ payoutAddress,
385
+ fromAmount,
386
+ seedIdFrom: mainFromAccount.seedIdentifier,
387
+ seedIdTo: toParentAccount?.seedIdentifier || toAccount?.seedIdentifier,
388
+ data: transaction.data
389
+ ? `0x${(0, hw_app_eth_1.padHexString)(transaction.data?.toString("hex") || "")}`
390
+ : "0x",
391
+ });
392
+ reject((0, parser_1.createStepError)({ error, step: parser_1.StepError.SIGNATURE }));
393
+ },
394
+ }));
395
+ }
396
+ catch (error) {
397
+ // Skip DrawerClosedError
398
+ // do not redirect to the error screen
399
+ if (isDrawerClosedError(error)) {
400
+ throw error;
401
+ }
402
+ // Global catch for any errors during the swap process
403
+ // moved out as sonarcloud suggested to avoid 4 level nested functions
404
+ const createErrorRejector = (error, reject) => {
405
+ return () => reject(error);
406
+ };
407
+ const displayError = (error) => new Promise((resolve, reject) => {
408
+ const rejectWithError = createErrorRejector(error, reject);
409
+ uiError({
410
+ error,
411
+ onSuccess: rejectWithError,
412
+ onCancel: rejectWithError,
366
413
  });
367
- reject(error);
368
- },
369
- }));
414
+ });
415
+ await (0, handleSwapErrors_1.handleErrors)(error, {
416
+ onDisplayError: displayError,
417
+ });
418
+ throw error;
419
+ }
370
420
  }),
371
421
  "custom.isReady": (0, wallet_api_server_1.customWrapper)(async () => {
372
422
  return new Promise((resolve, reject) => uiIsReady({
@@ -511,21 +561,20 @@ async function getStrategy({ recipient, amount, currency, customFeeConfig, payin
511
561
  convertedCustomFeeConfig[key] = new bignumber_js_1.BigNumber(value?.toString() || 0);
512
562
  }
513
563
  }
514
- try {
515
- return await strategy({
516
- family,
517
- amount: new bignumber_js_1.BigNumber(amount),
518
- recipient,
519
- customFeeConfig: convertedCustomFeeConfig,
520
- payinExtraId,
521
- extraTransactionParameters,
522
- customErrorType,
523
- sponsored,
524
- });
525
- }
526
- catch (error) {
527
- const errorMessage = error instanceof Error ? error.message : String(error);
528
- throw new Error(`Failed to execute transaction strategy for family: ${family}. Reason: ${errorMessage}`);
529
- }
564
+ return strategy({
565
+ family,
566
+ amount: new bignumber_js_1.BigNumber(amount),
567
+ recipient,
568
+ customFeeConfig: convertedCustomFeeConfig,
569
+ payinExtraId,
570
+ extraTransactionParameters,
571
+ customErrorType,
572
+ sponsored,
573
+ });
574
+ }
575
+ function isDrawerClosedError(error) {
576
+ if (!error || typeof error !== "object")
577
+ return false;
578
+ return ((0, get_1.default)(error, "name") === "DrawerClosedError" || (0, get_1.default)(error, "cause.name") === "DrawerClosedError");
530
579
  }
531
580
  //# sourceMappingURL=server.js.map