@ledgerhq/live-common 34.38.2-nightly.0 → 34.39.0-nightly.0

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 (118) hide show
  1. package/lib/bridge/cache.d.ts.map +1 -1
  2. package/lib/bridge/cache.js +2 -2
  3. package/lib/bridge/cache.js.map +1 -1
  4. package/lib/e2e/index.d.ts +0 -3
  5. package/lib/e2e/index.d.ts.map +1 -1
  6. package/lib/env.react.d.ts +1 -1
  7. package/lib/env.react.d.ts.map +1 -1
  8. package/lib/featureFlags/defaultFeatures.d.ts.map +1 -1
  9. package/lib/featureFlags/defaultFeatures.js +0 -11
  10. package/lib/featureFlags/defaultFeatures.js.map +1 -1
  11. package/lib/featureFlags/useFeature.d.ts +1 -1
  12. package/lib/featureFlags/useFeature.d.ts.map +1 -1
  13. package/lib/hw/connectAppEventMapper.d.ts.map +1 -1
  14. package/lib/hw/connectAppEventMapper.js +1 -3
  15. package/lib/hw/connectAppEventMapper.js.map +1 -1
  16. package/lib/wallet-api/types.d.ts +1 -1
  17. package/lib/wallet-api/types.d.ts.map +1 -1
  18. package/lib/wallet-api/useDappLogic.d.ts.map +1 -1
  19. package/lib/wallet-api/useDappLogic.js +24 -3
  20. package/lib/wallet-api/useDappLogic.js.map +1 -1
  21. package/lib-es/bridge/cache.d.ts.map +1 -1
  22. package/lib-es/bridge/cache.js +2 -2
  23. package/lib-es/bridge/cache.js.map +1 -1
  24. package/lib-es/e2e/index.d.ts +0 -3
  25. package/lib-es/e2e/index.d.ts.map +1 -1
  26. package/lib-es/env.react.d.ts +1 -1
  27. package/lib-es/env.react.d.ts.map +1 -1
  28. package/lib-es/featureFlags/defaultFeatures.d.ts.map +1 -1
  29. package/lib-es/featureFlags/defaultFeatures.js +0 -11
  30. package/lib-es/featureFlags/defaultFeatures.js.map +1 -1
  31. package/lib-es/featureFlags/useFeature.d.ts +1 -1
  32. package/lib-es/featureFlags/useFeature.d.ts.map +1 -1
  33. package/lib-es/hw/connectAppEventMapper.d.ts.map +1 -1
  34. package/lib-es/hw/connectAppEventMapper.js +1 -3
  35. package/lib-es/hw/connectAppEventMapper.js.map +1 -1
  36. package/lib-es/wallet-api/types.d.ts +1 -1
  37. package/lib-es/wallet-api/types.d.ts.map +1 -1
  38. package/lib-es/wallet-api/useDappLogic.d.ts.map +1 -1
  39. package/lib-es/wallet-api/useDappLogic.js +24 -3
  40. package/lib-es/wallet-api/useDappLogic.js.map +1 -1
  41. package/package.json +48 -48
  42. package/src/bridge/cache.ts +2 -5
  43. package/src/featureFlags/defaultFeatures.ts +0 -11
  44. package/src/hw/connectAppEventMapper.ts +1 -3
  45. package/src/wallet-api/types.ts +1 -1
  46. package/src/wallet-api/useDappLogic.ts +27 -4
  47. package/lib/bridge/cache.test.d.ts +0 -2
  48. package/lib/bridge/cache.test.d.ts.map +0 -1
  49. package/lib/bridge/cache.test.js +0 -63
  50. package/lib/bridge/cache.test.js.map +0 -1
  51. package/lib/hooks/useAppVersionBlockCheck.d.ts +0 -11
  52. package/lib/hooks/useAppVersionBlockCheck.d.ts.map +0 -1
  53. package/lib/hooks/useAppVersionBlockCheck.js +0 -32
  54. package/lib/hooks/useAppVersionBlockCheck.js.map +0 -1
  55. package/lib/hooks/useAppVersionBlockCheck.test.d.ts +0 -2
  56. package/lib/hooks/useAppVersionBlockCheck.test.d.ts.map +0 -1
  57. package/lib/hooks/useAppVersionBlockCheck.test.js +0 -133
  58. package/lib/hooks/useAppVersionBlockCheck.test.js.map +0 -1
  59. package/lib/modularDrawer/__test__/useModularDrawerVisibility.test.d.ts +0 -2
  60. package/lib/modularDrawer/__test__/useModularDrawerVisibility.test.d.ts.map +0 -1
  61. package/lib/modularDrawer/__test__/useModularDrawerVisibility.test.js +0 -107
  62. package/lib/modularDrawer/__test__/useModularDrawerVisibility.test.js.map +0 -1
  63. package/lib/modularDrawer/enums.d.ts +0 -8
  64. package/lib/modularDrawer/enums.d.ts.map +0 -1
  65. package/lib/modularDrawer/enums.js +0 -12
  66. package/lib/modularDrawer/enums.js.map +0 -1
  67. package/lib/modularDrawer/useModularDrawerVisibility.d.ts +0 -9
  68. package/lib/modularDrawer/useModularDrawerVisibility.d.ts.map +0 -1
  69. package/lib/modularDrawer/useModularDrawerVisibility.js +0 -18
  70. package/lib/modularDrawer/useModularDrawerVisibility.js.map +0 -1
  71. package/lib/wallet-api/utils/txTrackingHelper.d.ts +0 -3
  72. package/lib/wallet-api/utils/txTrackingHelper.d.ts.map +0 -1
  73. package/lib/wallet-api/utils/txTrackingHelper.js +0 -16
  74. package/lib/wallet-api/utils/txTrackingHelper.js.map +0 -1
  75. package/lib/wallet-api/utils/txTrackingHelper.test.d.ts +0 -2
  76. package/lib/wallet-api/utils/txTrackingHelper.test.d.ts.map +0 -1
  77. package/lib/wallet-api/utils/txTrackingHelper.test.js +0 -70
  78. package/lib/wallet-api/utils/txTrackingHelper.test.js.map +0 -1
  79. package/lib-es/bridge/cache.test.d.ts +0 -2
  80. package/lib-es/bridge/cache.test.d.ts.map +0 -1
  81. package/lib-es/bridge/cache.test.js +0 -38
  82. package/lib-es/bridge/cache.test.js.map +0 -1
  83. package/lib-es/hooks/useAppVersionBlockCheck.d.ts +0 -11
  84. package/lib-es/hooks/useAppVersionBlockCheck.d.ts.map +0 -1
  85. package/lib-es/hooks/useAppVersionBlockCheck.js +0 -25
  86. package/lib-es/hooks/useAppVersionBlockCheck.js.map +0 -1
  87. package/lib-es/hooks/useAppVersionBlockCheck.test.d.ts +0 -2
  88. package/lib-es/hooks/useAppVersionBlockCheck.test.d.ts.map +0 -1
  89. package/lib-es/hooks/useAppVersionBlockCheck.test.js +0 -131
  90. package/lib-es/hooks/useAppVersionBlockCheck.test.js.map +0 -1
  91. package/lib-es/modularDrawer/__test__/useModularDrawerVisibility.test.d.ts +0 -2
  92. package/lib-es/modularDrawer/__test__/useModularDrawerVisibility.test.d.ts.map +0 -1
  93. package/lib-es/modularDrawer/__test__/useModularDrawerVisibility.test.js +0 -105
  94. package/lib-es/modularDrawer/__test__/useModularDrawerVisibility.test.js.map +0 -1
  95. package/lib-es/modularDrawer/enums.d.ts +0 -8
  96. package/lib-es/modularDrawer/enums.d.ts.map +0 -1
  97. package/lib-es/modularDrawer/enums.js +0 -9
  98. package/lib-es/modularDrawer/enums.js.map +0 -1
  99. package/lib-es/modularDrawer/useModularDrawerVisibility.d.ts +0 -9
  100. package/lib-es/modularDrawer/useModularDrawerVisibility.d.ts.map +0 -1
  101. package/lib-es/modularDrawer/useModularDrawerVisibility.js +0 -14
  102. package/lib-es/modularDrawer/useModularDrawerVisibility.js.map +0 -1
  103. package/lib-es/wallet-api/utils/txTrackingHelper.d.ts +0 -3
  104. package/lib-es/wallet-api/utils/txTrackingHelper.d.ts.map +0 -1
  105. package/lib-es/wallet-api/utils/txTrackingHelper.js +0 -12
  106. package/lib-es/wallet-api/utils/txTrackingHelper.js.map +0 -1
  107. package/lib-es/wallet-api/utils/txTrackingHelper.test.d.ts +0 -2
  108. package/lib-es/wallet-api/utils/txTrackingHelper.test.d.ts.map +0 -1
  109. package/lib-es/wallet-api/utils/txTrackingHelper.test.js +0 -68
  110. package/lib-es/wallet-api/utils/txTrackingHelper.test.js.map +0 -1
  111. package/src/bridge/cache.test.ts +0 -46
  112. package/src/hooks/useAppVersionBlockCheck.test.ts +0 -134
  113. package/src/hooks/useAppVersionBlockCheck.ts +0 -65
  114. package/src/modularDrawer/__test__/useModularDrawerVisibility.test.ts +0 -149
  115. package/src/modularDrawer/enums.ts +0 -7
  116. package/src/modularDrawer/useModularDrawerVisibility.ts +0 -25
  117. package/src/wallet-api/utils/txTrackingHelper.test.ts +0 -80
  118. package/src/wallet-api/utils/txTrackingHelper.ts +0 -14
@@ -1,134 +0,0 @@
1
- import { useAppVersionBlockCheck } from "./useAppVersionBlockCheck";
2
-
3
- describe("useAppVersionBlockCheck", () => {
4
- describe("LLM", () => {
5
- it("should update if current version is not compatible on android", () => {
6
- // given
7
- const getConfigValue = () => ({
8
- llm: {
9
- android: [
10
- {
11
- minOsVersion: "32",
12
- version: "2.0.3",
13
- },
14
- ],
15
- },
16
- });
17
- // when
18
- const { shouldUpdate } = useAppVersionBlockCheck({
19
- appVersion: "2.0.1",
20
- osVersion: "32",
21
- platform: "android",
22
- appKey: "llm",
23
- getConfigValue,
24
- });
25
- //then
26
- expect(shouldUpdate).toBe(true);
27
- });
28
- it("should update if current version is not compatible on ios", () => {
29
- const getConfigValue = () => ({
30
- llm: {
31
- ios: [
32
- {
33
- minOsVersion: "32",
34
- version: "2.0.3",
35
- },
36
- ],
37
- },
38
- });
39
- // when
40
- const { shouldUpdate } = useAppVersionBlockCheck({
41
- appVersion: "2.0.1",
42
- osVersion: "32",
43
- platform: "ios",
44
- appKey: "llm",
45
- getConfigValue,
46
- });
47
- //then
48
- expect(shouldUpdate).toBe(true);
49
- });
50
- it("should not update the app if current version is not compatible on android with another os version", () => {
51
- // given
52
- const getConfigValue = () => ({
53
- llm: {
54
- android: [
55
- {
56
- minOsVersion: "33",
57
- version: "2.0.3",
58
- },
59
- ],
60
- },
61
- });
62
- // when
63
- const { shouldUpdate } = useAppVersionBlockCheck({
64
- appVersion: "2.0.1",
65
- osVersion: "32",
66
- platform: "android",
67
- appKey: "llm",
68
- getConfigValue,
69
- });
70
- //then
71
- expect(shouldUpdate).toBe(false);
72
- });
73
- it("should not update the app if current version is not compatible on ios with another os version", () => {
74
- // given
75
- const getConfigValue = () => ({
76
- llm: {
77
- ios: [
78
- {
79
- minOsVersion: "33",
80
- version: "2.0.3",
81
- },
82
- ],
83
- },
84
- });
85
- // when
86
- const { shouldUpdate } = useAppVersionBlockCheck({
87
- appVersion: "2.0.1",
88
- osVersion: "32",
89
- platform: "ios",
90
- appKey: "llm",
91
- getConfigValue,
92
- });
93
- //then
94
- expect(shouldUpdate).toBe(false);
95
- });
96
- it.each([
97
- ["android", "2.1.3"],
98
- ["ios", "2.1.3"],
99
- ["android", "2.1.3-rc.2"],
100
- ["ios", "2.1.3-rc.2"],
101
- ["android", "2.2.3-next.0"],
102
- ["ios", "2.2.3-next.0"],
103
- ["android", "2.0.3-rc2"],
104
- ["ios", "2.0.3-rc2"],
105
- ["android", "2.0.3-next.3"],
106
- ["ios", "2.0.3-next.3"],
107
- ])(
108
- "should not update the app on %s for version %s compatible with 2.0.3",
109
- (platform, appVersion) => {
110
- // given
111
- const getConfigValue = () => ({
112
- llm: {
113
- [platform]: [
114
- {
115
- minOsVersion: "32",
116
- version: "2.0.3",
117
- },
118
- ],
119
- },
120
- });
121
- // when
122
- const { shouldUpdate } = useAppVersionBlockCheck({
123
- appVersion,
124
- osVersion: "32",
125
- platform: platform as "ios" | "android",
126
- appKey: "llm",
127
- getConfigValue,
128
- });
129
- // then
130
- expect(shouldUpdate).toBe(false);
131
- },
132
- );
133
- });
134
- });
@@ -1,65 +0,0 @@
1
- import semver from "semver";
2
- import { LiveConfig } from "@ledgerhq/live-config/LiveConfig";
3
-
4
- type LLMMinVersionConfig = {
5
- minOsVersion: string;
6
- version: string;
7
- };
8
-
9
- type LLMinVersionConfig = {
10
- lld: {
11
- windows: string;
12
- macOS: string;
13
- linux: string;
14
- };
15
- llm: {
16
- android: LLMMinVersionConfig[];
17
- ios: LLMMinVersionConfig[];
18
- };
19
- };
20
-
21
- const checkLLmVersion = (
22
- appVersion: string,
23
- osVersion: string,
24
- platform: "ios" | "android",
25
- llmMinVersionConfig: LLMinVersionConfig["llm"],
26
- ) => {
27
- if (!llmMinVersionConfig[platform]) {
28
- return false;
29
- }
30
-
31
- return llmMinVersionConfig[platform]
32
- .filter(minVersionConfig =>
33
- semver.satisfies(semver.coerce(osVersion), `>=${minVersionConfig.minOsVersion}`),
34
- )
35
- .reduce((acc, curr) => {
36
- return acc || semver.satisfies(appVersion, `<${curr.version}`);
37
- }, false);
38
- };
39
-
40
- export const useAppVersionBlockCheck = ({
41
- appVersion: uncoercedAppVersion,
42
- appKey,
43
- platform,
44
- osVersion,
45
- getConfigValue = LiveConfig.getValueByKey,
46
- }: {
47
- appVersion: string;
48
- osVersion?: string;
49
- appKey: "llm" | "lld";
50
- platform: "ios" | "android" | "macOS" | "windows" | "linux";
51
- getConfigValue?: typeof LiveConfig.getValueByKey;
52
- }) => {
53
- const llMinVersionConfig = getConfigValue("config_ll_min_version");
54
- const appVersion = semver.coerce(uncoercedAppVersion)?.version || "";
55
- let shouldUpdate = false;
56
-
57
- if (!llMinVersionConfig) {
58
- return { shouldUpdate };
59
- }
60
-
61
- if (appKey === "llm" && (platform === "android" || platform === "ios") && osVersion) {
62
- shouldUpdate = checkLLmVersion(appVersion, osVersion, platform, llMinVersionConfig[appKey]);
63
- }
64
- return { shouldUpdate };
65
- };
@@ -1,149 +0,0 @@
1
- /**
2
- * @jest-environment jsdom
3
- */
4
- import { renderHook } from "@testing-library/react";
5
- import { useModularDrawerVisibility } from "../useModularDrawerVisibility";
6
- import { ModularDrawerLocation } from "../enums";
7
- import {
8
- makeMockedFeatureFlagsProviderWrapper,
9
- makeMockedContextValue,
10
- } from "../../featureFlags/mock";
11
-
12
- describe("useModularDrawerVisibility", () => {
13
- describe("lldModularDrawer", () => {
14
- it("should return false if the feature flag is not enabled", () => {
15
- const mockedFeatures = {
16
- lldModularDrawer: {
17
- enabled: false,
18
- params: { [ModularDrawerLocation.ADD_ACCOUNT]: true },
19
- },
20
- };
21
-
22
- const { result } = renderHook(
23
- () =>
24
- useModularDrawerVisibility({
25
- modularDrawerFeatureFlagKey: "lldModularDrawer",
26
- }),
27
- {
28
- wrapper: makeMockedFeatureFlagsProviderWrapper(makeMockedContextValue(mockedFeatures)),
29
- },
30
- );
31
-
32
- expect(result.current.isModularDrawerVisible(ModularDrawerLocation.ADD_ACCOUNT)).toBe(false);
33
- });
34
-
35
- it("should return false if the location param is not set", () => {
36
- const mockedFeatures = {
37
- lldModularDrawer: { enabled: true, params: {} },
38
- };
39
-
40
- const { result } = renderHook(
41
- () =>
42
- useModularDrawerVisibility({
43
- modularDrawerFeatureFlagKey: "lldModularDrawer",
44
- }),
45
- {
46
- wrapper: makeMockedFeatureFlagsProviderWrapper(makeMockedContextValue(mockedFeatures)),
47
- },
48
- );
49
-
50
- expect(result.current.isModularDrawerVisible(ModularDrawerLocation.ADD_ACCOUNT)).toBe(false);
51
- });
52
-
53
- it("should return the correct visibility for each location", () => {
54
- const mockedFeatures = {
55
- lldModularDrawer: {
56
- enabled: true,
57
- params: {
58
- [ModularDrawerLocation.ADD_ACCOUNT]: true,
59
- [ModularDrawerLocation.EARN_FLOW]: false,
60
- },
61
- },
62
- };
63
-
64
- const { result } = renderHook(
65
- () =>
66
- useModularDrawerVisibility({
67
- modularDrawerFeatureFlagKey: "lldModularDrawer",
68
- }),
69
- {
70
- wrapper: makeMockedFeatureFlagsProviderWrapper(makeMockedContextValue(mockedFeatures)),
71
- },
72
- );
73
-
74
- expect(result.current.isModularDrawerVisible(ModularDrawerLocation.ADD_ACCOUNT)).toBe(true);
75
- expect(result.current.isModularDrawerVisible(ModularDrawerLocation.EARN_FLOW)).toBe(false);
76
- expect(result.current.isModularDrawerVisible(ModularDrawerLocation.LIVE_APP)).toBe(false);
77
- });
78
- });
79
-
80
- describe("llmModularDrawer", () => {
81
- it("should return false if the feature flag is not enabled", () => {
82
- const mockedFeatures = {
83
- llmModularDrawer: {
84
- enabled: false,
85
- params: { [ModularDrawerLocation.ADD_ACCOUNT]: true },
86
- },
87
- };
88
-
89
- const { result } = renderHook(
90
- () =>
91
- useModularDrawerVisibility({
92
- modularDrawerFeatureFlagKey: "llmModularDrawer",
93
- }),
94
- {
95
- wrapper: makeMockedFeatureFlagsProviderWrapper(makeMockedContextValue(mockedFeatures)),
96
- },
97
- );
98
-
99
- expect(result.current.isModularDrawerVisible(ModularDrawerLocation.ADD_ACCOUNT)).toBe(false);
100
- });
101
-
102
- it("should return false if the location param is not set", () => {
103
- const mockedFeatures = {
104
- llmModularDrawer: { enabled: true, params: {} },
105
- };
106
-
107
- const { result } = renderHook(
108
- () =>
109
- useModularDrawerVisibility({
110
- modularDrawerFeatureFlagKey: "llmModularDrawer",
111
- }),
112
- {
113
- wrapper: makeMockedFeatureFlagsProviderWrapper(makeMockedContextValue(mockedFeatures)),
114
- },
115
- );
116
-
117
- expect(result.current.isModularDrawerVisible(ModularDrawerLocation.ADD_ACCOUNT)).toBe(false);
118
- });
119
-
120
- it("should return the correct visibility for each location", () => {
121
- const mockedFeatures = {
122
- llmModularDrawer: {
123
- enabled: true,
124
- params: {
125
- [ModularDrawerLocation.ADD_ACCOUNT]: false,
126
- [ModularDrawerLocation.EARN_FLOW]: true,
127
- [ModularDrawerLocation.RECEIVE_FLOW]: true,
128
- },
129
- },
130
- };
131
-
132
- const { result } = renderHook(
133
- () =>
134
- useModularDrawerVisibility({
135
- modularDrawerFeatureFlagKey: "llmModularDrawer",
136
- }),
137
- {
138
- wrapper: makeMockedFeatureFlagsProviderWrapper(makeMockedContextValue(mockedFeatures)),
139
- },
140
- );
141
-
142
- expect(result.current.isModularDrawerVisible(ModularDrawerLocation.ADD_ACCOUNT)).toBe(false);
143
- expect(result.current.isModularDrawerVisible(ModularDrawerLocation.EARN_FLOW)).toBe(true);
144
- expect(result.current.isModularDrawerVisible(ModularDrawerLocation.RECEIVE_FLOW)).toBe(true);
145
- expect(result.current.isModularDrawerVisible(ModularDrawerLocation.LIVE_APP)).toBe(false);
146
- expect(result.current.isModularDrawerVisible(ModularDrawerLocation.SEND_FLOW)).toBe(false);
147
- });
148
- });
149
- });
@@ -1,7 +0,0 @@
1
- export enum ModularDrawerLocation {
2
- ADD_ACCOUNT = "add_account",
3
- EARN_FLOW = "earn_flow",
4
- LIVE_APP = "live_app",
5
- RECEIVE_FLOW = "receive_flow",
6
- SEND_FLOW = "send_flow",
7
- }
@@ -1,25 +0,0 @@
1
- import { useCallback } from "react";
2
- import { useFeature } from "../featureFlags";
3
- import { ModularDrawerLocation } from "./enums";
4
-
5
- type ModularDrawerFeatureFlagKey = "lldModularDrawer" | "llmModularDrawer";
6
-
7
- export function useModularDrawerVisibility({
8
- modularDrawerFeatureFlagKey,
9
- }: {
10
- modularDrawerFeatureFlagKey: ModularDrawerFeatureFlagKey;
11
- }) {
12
- const featureModularDrawer = useFeature(modularDrawerFeatureFlagKey);
13
-
14
- const isModularDrawerVisible = useCallback(
15
- (location: ModularDrawerLocation) => {
16
- if (!featureModularDrawer?.enabled) return false;
17
- return featureModularDrawer.params?.[location] ?? false;
18
- },
19
- [featureModularDrawer],
20
- );
21
-
22
- return {
23
- isModularDrawerVisible,
24
- };
25
- }
@@ -1,80 +0,0 @@
1
- import { getTxType } from "./txTrackingHelper";
2
- import { ERC20_CLEAR_SIGNED_SELECTORS, DAPP_SELECTORS } from "@ledgerhq/hw-app-eth";
3
- import { Transaction as EvmTransaction } from "@ledgerhq/coin-evm/types/transaction";
4
-
5
- const createMockTransaction = (selector: string): EvmTransaction =>
6
- ({
7
- data: Buffer.from(selector.slice(2) + "0".repeat(128), "hex"),
8
- recipient: "0x1234567890123456789012345678901234567890",
9
- amount: "0",
10
- gasPrice: "0",
11
- gasLimit: "21000",
12
- nonce: 0,
13
- }) as unknown as EvmTransaction;
14
-
15
- describe("getTxType", () => {
16
- describe("ERC20 transactions", () => {
17
- it("should return 'transfer' for ERC20 transfer selector", () => {
18
- const tx = createMockTransaction(ERC20_CLEAR_SIGNED_SELECTORS.TRANSFER);
19
- const result = getTxType(tx);
20
- expect(result).toBe("transfer");
21
- });
22
-
23
- it("should return 'approve' for ERC20 approve selector", () => {
24
- const tx = createMockTransaction(ERC20_CLEAR_SIGNED_SELECTORS.APPROVE);
25
- const result = getTxType(tx);
26
- expect(result).toBe("approve");
27
- });
28
- });
29
-
30
- describe("DAPP transactions", () => {
31
- it("should return the DAPP selector value for known DAPP transactions", () => {
32
- const dappSelectors = Object.keys(DAPP_SELECTORS);
33
- if (dappSelectors.length > 0) {
34
- const firstSelector = dappSelectors[0];
35
- const expectedValue = DAPP_SELECTORS[firstSelector];
36
-
37
- const tx = createMockTransaction(firstSelector);
38
- const result = getTxType(tx);
39
- expect(result).toBe(expectedValue);
40
- }
41
- });
42
- });
43
-
44
- describe("Unknown transactions", () => {
45
- it("should return 'transfer' for unknown selectors", () => {
46
- const tx = createMockTransaction("0x12345678");
47
- const result = getTxType(tx);
48
- expect(result).toBe("transfer");
49
- });
50
-
51
- it("should return 'transfer' for transactions without data", () => {
52
- const tx = {
53
- data: undefined,
54
- } as EvmTransaction;
55
- const result = getTxType(tx);
56
- expect(result).toBe("transfer");
57
- });
58
-
59
- it("should return 'transfer' for transactions with empty data", () => {
60
- const tx = {
61
- data: Buffer.alloc(0),
62
- } as EvmTransaction;
63
- const result = getTxType(tx);
64
- expect(result).toBe("transfer");
65
- });
66
- });
67
-
68
- describe("Selector extract", () => {
69
- it("should correctly extract 4-byte selector from transaction data", () => {
70
- const transferSelector = ERC20_CLEAR_SIGNED_SELECTORS.TRANSFER;
71
- const tx = createMockTransaction(transferSelector);
72
-
73
- const expectedSelector = transferSelector;
74
- const txSelector = `0x${tx.data?.toString("hex").substring(0, 8)}`;
75
-
76
- expect(txSelector).toBe(expectedSelector);
77
- expect(getTxType(tx)).toBe("transfer");
78
- });
79
- });
80
- });
@@ -1,14 +0,0 @@
1
- import { Transaction as EvmTransaction } from "@ledgerhq/coin-evm/types/transaction";
2
- import { DAPP_SELECTORS } from "@ledgerhq/hw-app-eth";
3
-
4
- const fallback = "transfer";
5
-
6
- export const getTxType = (tx: EvmTransaction): string => {
7
- if (!tx || !tx.data) return fallback;
8
-
9
- const txSelector = `0x${tx.data.toString("hex").substring(0, 8)}`;
10
- const type = DAPP_SELECTORS[txSelector];
11
-
12
- if (!type) return fallback;
13
- return type;
14
- };