zh-web-sdk 2.16.1 → 2.17.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 (51) hide show
  1. package/README.md +225 -32
  2. package/package.json +6 -1
  3. package/.eslintrc.js +0 -12
  4. package/.github/CHANGELOG_TEMPLATE.md +0 -73
  5. package/.github/PULL_REQUEST_TEMPLATE.md +0 -10
  6. package/.github/backup/publish-tag.yaml +0 -14
  7. package/.github/workflows/build.yaml +0 -13
  8. package/.github/workflows/pr.yaml +0 -14
  9. package/.github/workflows/publish.yaml +0 -13
  10. package/.github/workflows/security.yml +0 -15
  11. package/.github/workflows/tag.yaml +0 -14
  12. package/RELEASING.md +0 -39
  13. package/jest.config.js +0 -8
  14. package/jest.setup.js +0 -24
  15. package/scripts/build.js +0 -34
  16. package/scripts/zip.js +0 -49
  17. package/src/__tests__/jwt-auth-detection.test.ts +0 -96
  18. package/src/api/convert-token.ts +0 -23
  19. package/src/constants.ts +0 -2
  20. package/src/hooks/__tests__/use-window-size.test.tsx +0 -26
  21. package/src/hooks/use-window-size.ts +0 -19
  22. package/src/iframe-container/AppContainer.tsx +0 -495
  23. package/src/iframe-container/__tests__/AppContainer.test.tsx +0 -300
  24. package/src/iframe-container/hooks/__tests__/use-style-updates.test.ts +0 -430
  25. package/src/iframe-container/hooks/use-style-updates.ts +0 -82
  26. package/src/index.tsx +0 -645
  27. package/src/redux/actions/index.ts +0 -27
  28. package/src/redux/reducers/constants.ts +0 -10
  29. package/src/redux/reducers/crypto-account-link-payouts.ts +0 -60
  30. package/src/redux/reducers/crypto-account-link.ts +0 -60
  31. package/src/redux/reducers/crypto-buy.ts +0 -75
  32. package/src/redux/reducers/crypto-sell.ts +0 -64
  33. package/src/redux/reducers/crypto-withdrawals.ts +0 -64
  34. package/src/redux/reducers/fiat-account-link.ts +0 -60
  35. package/src/redux/reducers/fiat-deposits.ts +0 -64
  36. package/src/redux/reducers/fiat-withdrawals.ts +0 -64
  37. package/src/redux/reducers/fund.ts +0 -75
  38. package/src/redux/reducers/index.ts +0 -35
  39. package/src/redux/reducers/onboarding.ts +0 -74
  40. package/src/redux/reducers/pay.ts +0 -64
  41. package/src/redux/reducers/payouts.ts +0 -64
  42. package/src/redux/reducers/profile.ts +0 -63
  43. package/src/redux/store/index.ts +0 -10
  44. package/src/styles.ts +0 -108
  45. package/src/types.ts +0 -578
  46. package/src/utils/auth-to-fund-mapper.ts +0 -174
  47. package/src/utils/strings.ts +0 -19
  48. package/src/utils/test-utils.tsx +0 -36
  49. package/src/utils/world-app-utils.ts +0 -8
  50. package/src/utils.ts +0 -27
  51. package/tsconfig.json +0 -26
@@ -1,174 +0,0 @@
1
- /**
2
- * Auth to Fund Event Mapper
3
- *
4
- * This module provides utilities to map Connect Auth callbacks to Fund postMessage events
5
- * for backward compatibility. When using @connect-xyz/auth-react instead of Fund iframe,
6
- * we need to translate Auth's callback-based API into Fund's postMessage-based API.
7
- *
8
- * Mapping:
9
- * - Auth onLoaded() -> FUND_APP_LOADED
10
- * - Auth onClose() -> FUND_CLOSE_BUTTON_CLICKED
11
- * - Auth onDeposit() with success status -> FUND_COMPLETED
12
- * - Auth onDeposit() with failed status -> FUND_FAILED
13
- * - Auth onError() -> FUND_ERROR (new event)
14
- * - Auth onEvent('deposit.submitted') -> FUND_DEPOSIT_SUBMITTED (new event)
15
- */
16
-
17
- import { IncomingMessageType } from "../types";
18
-
19
- /**
20
- * Auth callback types from @connect-xyz/auth-react
21
- */
22
- export type AuthDepositPayload = {
23
- data: {
24
- depositId: string;
25
- status: {
26
- value: string;
27
- details: string;
28
- occurredAt: string;
29
- };
30
- assetId: string;
31
- networkId: string;
32
- amount?: string;
33
- };
34
- };
35
-
36
- export type AuthErrorPayload = {
37
- errorCode: string;
38
- reason: string;
39
- };
40
-
41
- export type AuthEvent = {
42
- type: string;
43
- data: {
44
- depositId: string;
45
- };
46
- };
47
-
48
- /**
49
- * Creates Auth callbacks that automatically emit Fund-compatible postMessages
50
- * to the parent window for backward compatibility.
51
- *
52
- * @param origin - The origin to send postMessages to (typically window.location.origin)
53
- * @returns Object with Auth callback functions
54
- */
55
- export function createAuthToFundCallbacks(origin: string) {
56
- const sendPostMessage = (type: IncomingMessageType, payload?: unknown) => {
57
- window.postMessage(
58
- {
59
- type,
60
- payload,
61
- },
62
- origin
63
- );
64
- };
65
-
66
- return {
67
- /**
68
- * Maps Auth onLoaded to FUND_APP_LOADED
69
- */
70
- onLoaded: () => {
71
- sendPostMessage(IncomingMessageType.StyleConfig)
72
- sendPostMessage(IncomingMessageType.FundAppLoaded);
73
- },
74
-
75
- /**
76
- * Maps Auth onClose to FUND_CLOSE_BUTTON_CLICKED
77
- */
78
- onClose: () => {
79
- sendPostMessage(IncomingMessageType.FundCloseButtonClicked);
80
- },
81
-
82
- /**
83
- * Maps Auth onDeposit to FUND_COMPLETED or FUND_FAILED
84
- * based on the deposit status value.
85
- * Also sends FUND_CONNECT_DEPOSIT event for Connect-specific deposit handling.
86
- */
87
- onDeposit: (deposit: AuthDepositPayload) => {
88
- const isSuccess = isDepositSuccessful(deposit.data.status.value);
89
-
90
- const payload = {
91
- transactionId: deposit.data.depositId,
92
- fundId: deposit.data.depositId,
93
- assetId: deposit.data.assetId,
94
- networkId: deposit.data.networkId,
95
- amount: deposit.data.amount,
96
- status: deposit.data.status,
97
- };
98
-
99
- // Send Connect-specific deposit event (new event exclusive to Connect Auth)
100
- sendPostMessage(IncomingMessageType.FundConnectDeposit, payload);
101
-
102
- // Send legacy FUND_COMPLETED or FUND_FAILED for backward compatibility
103
- if (isSuccess) {
104
- sendPostMessage(IncomingMessageType.FundCompleted, payload);
105
- } else {
106
- sendPostMessage(IncomingMessageType.FundFailed, payload);
107
- }
108
- },
109
-
110
- /**
111
- * Maps Auth onError to FUND_ERROR
112
- */
113
- onError: (error: AuthErrorPayload) => {
114
- sendPostMessage(IncomingMessageType.StyleConfig);
115
- sendPostMessage(IncomingMessageType.FundError, {
116
- errorCode: error.errorCode,
117
- reason: error.reason,
118
- });
119
- },
120
-
121
- /**
122
- * Maps Auth onEvent to appropriate Fund events
123
- * Handles 'deposit.submitted' -> FUND_DEPOSIT_SUBMITTED
124
- * All other events are caught by default case -> FUND_CONNECT_EVENT (catch-all)
125
- */
126
- onEvent: (event: AuthEvent) => {
127
- if (event.type === 'deposit.submitted') {
128
- sendPostMessage(IncomingMessageType.FundDepositSubmitted, {
129
- depositId: event.data.depositId,
130
- });
131
- } else {
132
- // Default case: catch-all for any other Auth events
133
- sendPostMessage(IncomingMessageType.FundConnectEvent, {
134
- type: event.type,
135
- data: event.data,
136
- });
137
- }
138
- },
139
- };
140
- }
141
-
142
- /**
143
- * Determines if a deposit was successful based on the status value
144
- * @param statusValue - The status value from the deposit
145
- * @returns true if deposit was successful, false otherwise
146
- */
147
- function isDepositSuccessful(statusValue: string): boolean {
148
- const successStatuses = [
149
- 'completed',
150
- 'success',
151
- 'confirmed',
152
- 'settled',
153
- 'processed',
154
- ];
155
-
156
- const failureStatuses = [
157
- 'failed',
158
- 'rejected',
159
- 'cancelled',
160
- 'error',
161
- ];
162
-
163
- const normalizedStatus = statusValue.toLowerCase();
164
-
165
- if (successStatuses.includes(normalizedStatus)) {
166
- return true;
167
- }
168
-
169
- if (failureStatuses.includes(normalizedStatus)) {
170
- return false;
171
- }
172
-
173
- return false;
174
- }
@@ -1,19 +0,0 @@
1
- /**
2
- * randomString generates a random string of specified
3
- * @param length
4
- * @param characters - charset to be used.
5
- */
6
- export const randomString = (
7
- length: number,
8
- characters: string = 'abcdefghijklmnopqrstuvwxyz0123456789'
9
- ) => {
10
- let result = '';
11
- const charactersLength = characters.length;
12
- let counter = 0;
13
- while (counter < length) {
14
- result += characters.charAt(Math.floor(Math.random() * charactersLength));
15
- counter += 1;
16
- }
17
- return result;
18
- }
19
-
@@ -1,36 +0,0 @@
1
- import React, { PropsWithChildren } from 'react'
2
- import { render } from '@testing-library/react'
3
- import type { RenderOptions } from '@testing-library/react'
4
- import { legacy_createStore as createStore } from "redux"
5
- import { Provider } from 'react-redux'
6
- import rootReducer from "../redux/reducers";
7
- import {AppStore, RootState} from "../redux/store";
8
-
9
- // This type interface extends the default options for render from RTL, as well
10
- // as allows the user to specify other things such as initialState, store.
11
- interface ExtendedRenderOptions extends Omit<RenderOptions, 'queries'> {
12
- preloadedState?: Partial<RootState>
13
- store?: AppStore
14
- }
15
-
16
- export function renderWithProviders(
17
- ui: React.ReactElement,
18
- extendedRenderOptions: ExtendedRenderOptions = {}
19
- ) {
20
- const {
21
- preloadedState = {},
22
- // Automatically create a store instance if no store was passed in
23
- store = createStore(rootReducer, preloadedState),
24
- ...renderOptions
25
- } = extendedRenderOptions
26
-
27
- const Wrapper = ({ children }: PropsWithChildren) => (
28
- <Provider store={store}>{children}</Provider>
29
- )
30
-
31
- // Return an object with the store and all of RTL's query functions
32
- return {
33
- store,
34
- ...render(ui, { wrapper: Wrapper, ...renderOptions })
35
- }
36
- }
@@ -1,8 +0,0 @@
1
- const isInsideWorldApp = (): boolean => {
2
- if (!window) return false
3
- return !!window.WorldApp;
4
- }
5
-
6
- export {
7
- isInsideWorldApp
8
- }
package/src/utils.ts DELETED
@@ -1,27 +0,0 @@
1
- import { randomString } from "./utils/strings";
2
- import { DEFAULT_ROOT_ID_PREFIX } from "./constants";
3
- import { AppIdentifier, appIdentifierToActionPrefixMap } from "./types";
4
- import store from "./redux/store";
5
-
6
- /**
7
- * generateRootID attempts to create a dynamic ID to be
8
- * used with a HTML element that is relatively unique
9
- * and will not cause namespace conflicts.
10
- *
11
- * E.g. 'zerohash-49vt8y'
12
- */
13
- export const generateRootID = (appIdentifier?: AppIdentifier): string => {
14
- if (appIdentifier) return `${DEFAULT_ROOT_ID_PREFIX}-${appIdentifier}-${randomString(6)}`
15
- return `${DEFAULT_ROOT_ID_PREFIX}-${randomString(6)}`
16
- };
17
-
18
- export const dispatchActionBasedOnAppIdentifier = (appIdentifier: AppIdentifier, actionTypeSuffix: string, payload: object) => {
19
- const actionTypePrefix = appIdentifierToActionPrefixMap.get(appIdentifier)
20
- const type = `${actionTypePrefix}${actionTypeSuffix}`
21
- store.dispatch({
22
- type,
23
- ...payload,
24
- })
25
- }
26
-
27
-
package/tsconfig.json DELETED
@@ -1,26 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "declaration": true,
4
- "target": "esnext",
5
- "lib": [
6
- "dom",
7
- "dom.iterable",
8
- "esnext"
9
- ],
10
- "allowJs": true,
11
- "skipLibCheck": true,
12
- "esModuleInterop": true,
13
- "allowSyntheticDefaultImports": true,
14
- "strict": true,
15
- "forceConsistentCasingInFileNames": true,
16
- "noFallthroughCasesInSwitch": true,
17
- "module": "esnext",
18
- "moduleResolution": "node",
19
- "resolveJsonModule": true,
20
- "isolatedModules": true,
21
- "jsx": "react-jsx"
22
- },
23
- "include": [
24
- "src"
25
- ]
26
- }