@gala-chain/gswap-sdk 1.2.0 → 2.0.0-rc.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.
- package/README.md +42 -8
- package/dist/browser/classes/apply_results.js +1 -1
- package/dist/browser/classes/apply_results.js.map +1 -1
- package/dist/browser/classes/assets.js +1 -1
- package/dist/browser/classes/assets.js.map +1 -1
- package/dist/browser/classes/dex_fees.js +1 -1
- package/dist/browser/classes/dex_fees.js.map +1 -1
- package/dist/browser/classes/gateway.js +1 -1
- package/dist/browser/classes/gateway.js.map +1 -1
- package/dist/browser/classes/gdex_stream.js +1 -1
- package/dist/browser/classes/gdex_stream.js.map +1 -1
- package/dist/browser/classes/gswap.js +1 -1
- package/dist/browser/classes/gswap.js.map +1 -1
- package/dist/browser/classes/gswap_error_catalog.js +2 -0
- package/dist/browser/classes/gswap_error_catalog.js.map +1 -0
- package/dist/browser/classes/gswap_error_phase_table.js +2 -0
- package/dist/browser/classes/gswap_error_phase_table.js.map +1 -0
- package/dist/browser/classes/gswap_sdk_error.js +1 -1
- package/dist/browser/classes/gswap_sdk_error.js.map +1 -1
- package/dist/browser/classes/http_client.js +1 -1
- package/dist/browser/classes/http_client.js.map +1 -1
- package/dist/browser/classes/leaderboard.js +2 -0
- package/dist/browser/classes/leaderboard.js.map +1 -0
- package/dist/browser/classes/market.js +2 -0
- package/dist/browser/classes/market.js.map +1 -0
- package/dist/browser/classes/pending_swap_fate.js.map +1 -1
- package/dist/browser/classes/pending_swaps.js +1 -1
- package/dist/browser/classes/pending_swaps.js.map +1 -1
- package/dist/browser/classes/pools.js +1 -1
- package/dist/browser/classes/pools.js.map +1 -1
- package/dist/browser/classes/positions.js +1 -1
- package/dist/browser/classes/positions.js.map +1 -1
- package/dist/browser/classes/quoting.js +1 -1
- package/dist/browser/classes/quoting.js.map +1 -1
- package/dist/browser/classes/shadow_submit.js.map +1 -1
- package/dist/browser/classes/storage_adapters.js.map +1 -1
- package/dist/browser/classes/submitted_transaction.js +1 -1
- package/dist/browser/classes/submitted_transaction.js.map +1 -1
- package/dist/browser/classes/swaps.js +1 -1
- package/dist/browser/classes/swaps.js.map +1 -1
- package/dist/browser/classes/symbols.js +1 -1
- package/dist/browser/classes/symbols.js.map +1 -1
- package/dist/browser/index.js +1 -1
- package/dist/browser/types/env.js.map +1 -1
- package/dist/browser/types/fees.js.map +1 -1
- package/dist/browser/types/market.js +2 -0
- package/dist/browser/types/market.js.map +1 -0
- package/dist/browser/utils/classification.js.map +1 -1
- package/dist/browser/utils/confirmation_schedule.js.map +1 -1
- package/dist/browser/utils/confirmation_state.js +1 -1
- package/dist/browser/utils/confirmation_state.js.map +1 -1
- package/dist/browser/utils/debug.js.map +1 -1
- package/dist/browser/utils/dto_builders.js +1 -1
- package/dist/browser/utils/dto_builders.js.map +1 -1
- package/dist/browser/utils/failure_classification.js +1 -1
- package/dist/browser/utils/failure_classification.js.map +1 -1
- package/dist/browser/utils/failure_guards.js +1 -1
- package/dist/browser/utils/failure_guards.js.map +1 -1
- package/dist/browser/utils/lenient.js +1 -1
- package/dist/browser/utils/lenient.js.map +1 -1
- package/dist/browser/utils/ordering.js +1 -1
- package/dist/browser/utils/ordering.js.map +1 -1
- package/dist/browser/utils/reconnection.js +1 -1
- package/dist/browser/utils/reconnection.js.map +1 -1
- package/dist/browser/utils/resolve_pre_send.js +2 -0
- package/dist/browser/utils/resolve_pre_send.js.map +1 -0
- package/dist/browser/utils/server_message.js.map +1 -1
- package/dist/browser/utils/shadow_errors.js +1 -1
- package/dist/browser/utils/shadow_errors.js.map +1 -1
- package/dist/browser/utils/submit_state.js.map +1 -1
- package/dist/browser/utils/tick_align.js.map +1 -1
- package/dist/browser/utils/tick_math.js.map +1 -1
- package/dist/browser/utils/tick_range.js.map +1 -1
- package/dist/browser/utils/ticks.js +1 -1
- package/dist/browser/utils/ticks.js.map +1 -1
- package/dist/browser/utils/validation.js +1 -1
- package/dist/browser/utils/validation.js.map +1 -1
- package/dist/index.cjs +1033 -2925
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +439 -1604
- package/dist/index.d.ts +439 -1604
- package/dist/index.mjs +964 -2810
- package/dist/index.mjs.map +1 -1
- package/package.json +36 -60
- package/dist/browser/classes/error_catalog.js +0 -2
- package/dist/browser/classes/error_catalog.js.map +0 -1
- package/dist/browser/classes/error_phase_table.js +0 -2
- package/dist/browser/classes/error_phase_table.js.map +0 -1
- package/dist/browser/classes/error_phases.js +0 -2
- package/dist/browser/classes/error_phases.js.map +0 -1
- package/dist/browser/classes/signers.js +0 -2
- package/dist/browser/classes/signers.js.map +0 -1
- package/dist/browser/utils/axios_requestor.js +0 -2
- package/dist/browser/utils/axios_requestor.js.map +0 -1
- package/dist/browser/utils/chain_dto_signing.js +0 -3
- package/dist/browser/utils/chain_dto_signing.js.map +0 -1
- package/dist/browser/utils/class_key.js +0 -2
- package/dist/browser/utils/class_key.js.map +0 -1
- package/dist/browser/utils/eip712.js +0 -4
- package/dist/browser/utils/eip712.js.map +0 -1
- package/dist/browser/utils/error_brand.js +0 -2
- package/dist/browser/utils/error_brand.js.map +0 -1
- package/dist/browser/utils/ethers_provider.js +0 -2
- package/dist/browser/utils/ethers_provider.js.map +0 -1
- package/dist/browser/utils/failure_outcomes.js +0 -2
- package/dist/browser/utils/failure_outcomes.js.map +0 -1
- package/dist/browser/utils/failure_view.js +0 -2
- package/dist/browser/utils/failure_view.js.map +0 -1
- package/dist/browser/utils/fetch_failure.js +0 -2
- package/dist/browser/utils/fetch_failure.js.map +0 -1
- package/dist/browser/utils/pre_send.js +0 -2
- package/dist/browser/utils/pre_send.js.map +0 -1
- package/dist/browser/utils/signing.js +0 -3
- package/dist/browser/utils/signing.js.map +0 -1
- package/dist/browser/utils/transport.js +0 -2
- package/dist/browser/utils/transport.js.map +0 -1
- package/dist/browser/utils/typed_data.js +0 -2
- package/dist/browser/utils/typed_data.js.map +0 -1
- package/dist/browser/utils/unique_key.js +0 -2
- package/dist/browser/utils/unique_key.js.map +0 -1
- package/dist/browser/utils/unique_key_syntax.js +0 -2
- package/dist/browser/utils/unique_key_syntax.js.map +0 -1
- package/dist/browser/utils/wallet_rejection.js +0 -2
- package/dist/browser/utils/wallet_rejection.js.map +0 -1
- package/dist/browser/version.js +0 -2
- package/dist/browser/version.js.map +0 -1
- package/dist/browser/wallet.js +0 -2
- package/dist/browser/wallet.js.map +0 -1
- package/dist/wallet.cjs +0 -159
- package/dist/wallet.cjs.map +0 -1
- package/dist/wallet.d.cts +0 -74
- package/dist/wallet.d.ts +0 -74
- package/dist/wallet.mjs +0 -156
- package/dist/wallet.mjs.map +0 -1
- /package/dist/browser/_virtual/{_@oxc-project_runtime@0.151.0 → _@oxc-project_runtime@0.153.0}/helpers/esm/defineProperty.js +0 -0
- /package/dist/browser/_virtual/{_@oxc-project_runtime@0.151.0 → _@oxc-project_runtime@0.153.0}/helpers/esm/toPrimitive.js +0 -0
- /package/dist/browser/_virtual/{_@oxc-project_runtime@0.151.0 → _@oxc-project_runtime@0.153.0}/helpers/esm/toPropertyKey.js +0 -0
- /package/dist/browser/_virtual/{_@oxc-project_runtime@0.151.0 → _@oxc-project_runtime@0.153.0}/helpers/esm/typeof.js +0 -0
package/dist/wallet.d.cts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
//#region src/utils/error_brand.d.ts
|
|
2
|
-
/** The least an object must have to be read as an SDK error or its plain-object view. */
|
|
3
|
-
interface GSwapErrorShape {
|
|
4
|
-
readonly code: string;
|
|
5
|
-
readonly params: Readonly<Record<string, unknown>>;
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* True when `value` is an SDK error (it carries the brand) or a plain-object VIEW of one: a string
|
|
9
|
-
* `code` and an object `params`, which is the shape of `GSwapSDKError` and of the wrapper objects
|
|
10
|
-
* an app builds from one (`{ code, params, status?, phase?, ... }`). A wallet's own error (an
|
|
11
|
-
* EIP-1193 numeric `code`, an ethers error with a string `code` and no `params`) is neither. It
|
|
12
|
-
* says the value has the SDK's shape, not that `code` is a code the SDK knows.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```ts
|
|
16
|
-
* if (isGSwapErrorLike(error)) report(error.code, error.params); // no `instanceof`, no SDK import
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
19
|
-
export declare function isGSwapErrorLike(value: unknown): value is GSwapErrorShape;
|
|
20
|
-
//#endregion
|
|
21
|
-
//#region src/utils/wallet_rejection.d.ts
|
|
22
|
-
/**
|
|
23
|
-
* What the SDK knows about a failure thrown by a WALLET (the signer an app supplies, or wallet
|
|
24
|
-
* code of the app's own): the code the wallet put on it, and whether it means the person declined.
|
|
25
|
-
* Both read only the wallet's own error value; neither shows or forwards its text.
|
|
26
|
-
*/
|
|
27
|
-
/**
|
|
28
|
-
* True when a wallet's error (or just its message text) says the person DECLINED the request in
|
|
29
|
-
* their wallet. This is exactly the test behind `SIGNING_FAILED` with `params.reason ===
|
|
30
|
-
* 'user_rejected'`, exported for wallet code outside the SDK (connect and registration flows, a
|
|
31
|
-
* v1 write path) so an app keeps no matcher of its own.
|
|
32
|
-
*
|
|
33
|
-
* It is decided from the wallet's own fields first: a `code` of `4001` (EIP-1193), `'ACTION_REJECTED'`
|
|
34
|
-
* (ethers) or `'USER_REJECTED'`, or `name === 'UserRejectedRequestError'` (viem). Only when those are
|
|
35
|
-
* absent is the wallet's TEXT read (`message`, `Message`, `shortMessage`, `details`, `errorDetails`,
|
|
36
|
-
* `reason`, up to three levels deep, or a bare string): "user rejected", "user denied", "user
|
|
37
|
-
* cancelled", "request rejected", "rejected by user", "rejected the request", "cancelled" /
|
|
38
|
-
* "canceled", or a "signature ... cancel" sentence. The wording fallback is a last resort for
|
|
39
|
-
* wallets that do not set codes; prefer `code` and `name` wherever you control the wallet.
|
|
40
|
-
*
|
|
41
|
-
* An SDK error is never read by its text: a `SIGNING_FAILED` is a decline exactly when its
|
|
42
|
-
* `params.reason` is `user_rejected`, and every other SDK error is not one. The same holds for a
|
|
43
|
-
* plain-object VIEW of an SDK error (`{ code: 'SIGNING_FAILED', params: { reason } }`, the shape
|
|
44
|
-
* of an app's wrapper): a string `code` plus an object `params` is decided by the code alone, with
|
|
45
|
-
* the wallet code list above still honoured for a view that is not branded, and its English is
|
|
46
|
-
* never read. This works without `instanceof`, so it is safe across two copies of the SDK.
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* ```ts
|
|
50
|
-
* try {
|
|
51
|
-
* await wallet.connect();
|
|
52
|
-
* } catch (error) {
|
|
53
|
-
* if (isWalletUserRejection(error)) return; // the person said no: not an error to report
|
|
54
|
-
* report(error);
|
|
55
|
-
* }
|
|
56
|
-
* ```
|
|
57
|
-
*/
|
|
58
|
-
export declare function isWalletUserRejection(value: unknown): boolean;
|
|
59
|
-
/**
|
|
60
|
-
* The code a wallet put on its error: an EIP-1193 / JSON-RPC number (`4001`, `-32603`) or an
|
|
61
|
-
* ethers / viem string (`'ACTION_REJECTED'`), read from the error's own top-level `code`. Anything
|
|
62
|
-
* else (no code, a non-finite number, an empty or very long string, an object) is `undefined`, so
|
|
63
|
-
* the value is always a safe primitive. Used for `GSwapSDKError.walletCode`.
|
|
64
|
-
*
|
|
65
|
-
* @example
|
|
66
|
-
* ```ts
|
|
67
|
-
* walletDeclineCode({ code: 4001, message: 'User rejected the request.' }); // 4001
|
|
68
|
-
* walletDeclineCode(new Error('locked')); // undefined
|
|
69
|
-
* ```
|
|
70
|
-
*/
|
|
71
|
-
export declare function walletDeclineCode(value: unknown): number | string | undefined;
|
|
72
|
-
//#endregion
|
|
73
|
-
export type { GSwapErrorShape };
|
|
74
|
-
//# sourceMappingURL=wallet.d.cts.map
|
package/dist/wallet.d.ts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
//#region src/utils/error_brand.d.ts
|
|
2
|
-
/** The least an object must have to be read as an SDK error or its plain-object view. */
|
|
3
|
-
interface GSwapErrorShape {
|
|
4
|
-
readonly code: string;
|
|
5
|
-
readonly params: Readonly<Record<string, unknown>>;
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* True when `value` is an SDK error (it carries the brand) or a plain-object VIEW of one: a string
|
|
9
|
-
* `code` and an object `params`, which is the shape of `GSwapSDKError` and of the wrapper objects
|
|
10
|
-
* an app builds from one (`{ code, params, status?, phase?, ... }`). A wallet's own error (an
|
|
11
|
-
* EIP-1193 numeric `code`, an ethers error with a string `code` and no `params`) is neither. It
|
|
12
|
-
* says the value has the SDK's shape, not that `code` is a code the SDK knows.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```ts
|
|
16
|
-
* if (isGSwapErrorLike(error)) report(error.code, error.params); // no `instanceof`, no SDK import
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
19
|
-
export declare function isGSwapErrorLike(value: unknown): value is GSwapErrorShape;
|
|
20
|
-
//#endregion
|
|
21
|
-
//#region src/utils/wallet_rejection.d.ts
|
|
22
|
-
/**
|
|
23
|
-
* What the SDK knows about a failure thrown by a WALLET (the signer an app supplies, or wallet
|
|
24
|
-
* code of the app's own): the code the wallet put on it, and whether it means the person declined.
|
|
25
|
-
* Both read only the wallet's own error value; neither shows or forwards its text.
|
|
26
|
-
*/
|
|
27
|
-
/**
|
|
28
|
-
* True when a wallet's error (or just its message text) says the person DECLINED the request in
|
|
29
|
-
* their wallet. This is exactly the test behind `SIGNING_FAILED` with `params.reason ===
|
|
30
|
-
* 'user_rejected'`, exported for wallet code outside the SDK (connect and registration flows, a
|
|
31
|
-
* v1 write path) so an app keeps no matcher of its own.
|
|
32
|
-
*
|
|
33
|
-
* It is decided from the wallet's own fields first: a `code` of `4001` (EIP-1193), `'ACTION_REJECTED'`
|
|
34
|
-
* (ethers) or `'USER_REJECTED'`, or `name === 'UserRejectedRequestError'` (viem). Only when those are
|
|
35
|
-
* absent is the wallet's TEXT read (`message`, `Message`, `shortMessage`, `details`, `errorDetails`,
|
|
36
|
-
* `reason`, up to three levels deep, or a bare string): "user rejected", "user denied", "user
|
|
37
|
-
* cancelled", "request rejected", "rejected by user", "rejected the request", "cancelled" /
|
|
38
|
-
* "canceled", or a "signature ... cancel" sentence. The wording fallback is a last resort for
|
|
39
|
-
* wallets that do not set codes; prefer `code` and `name` wherever you control the wallet.
|
|
40
|
-
*
|
|
41
|
-
* An SDK error is never read by its text: a `SIGNING_FAILED` is a decline exactly when its
|
|
42
|
-
* `params.reason` is `user_rejected`, and every other SDK error is not one. The same holds for a
|
|
43
|
-
* plain-object VIEW of an SDK error (`{ code: 'SIGNING_FAILED', params: { reason } }`, the shape
|
|
44
|
-
* of an app's wrapper): a string `code` plus an object `params` is decided by the code alone, with
|
|
45
|
-
* the wallet code list above still honoured for a view that is not branded, and its English is
|
|
46
|
-
* never read. This works without `instanceof`, so it is safe across two copies of the SDK.
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* ```ts
|
|
50
|
-
* try {
|
|
51
|
-
* await wallet.connect();
|
|
52
|
-
* } catch (error) {
|
|
53
|
-
* if (isWalletUserRejection(error)) return; // the person said no: not an error to report
|
|
54
|
-
* report(error);
|
|
55
|
-
* }
|
|
56
|
-
* ```
|
|
57
|
-
*/
|
|
58
|
-
export declare function isWalletUserRejection(value: unknown): boolean;
|
|
59
|
-
/**
|
|
60
|
-
* The code a wallet put on its error: an EIP-1193 / JSON-RPC number (`4001`, `-32603`) or an
|
|
61
|
-
* ethers / viem string (`'ACTION_REJECTED'`), read from the error's own top-level `code`. Anything
|
|
62
|
-
* else (no code, a non-finite number, an empty or very long string, an object) is `undefined`, so
|
|
63
|
-
* the value is always a safe primitive. Used for `GSwapSDKError.walletCode`.
|
|
64
|
-
*
|
|
65
|
-
* @example
|
|
66
|
-
* ```ts
|
|
67
|
-
* walletDeclineCode({ code: 4001, message: 'User rejected the request.' }); // 4001
|
|
68
|
-
* walletDeclineCode(new Error('locked')); // undefined
|
|
69
|
-
* ```
|
|
70
|
-
*/
|
|
71
|
-
export declare function walletDeclineCode(value: unknown): number | string | undefined;
|
|
72
|
-
//#endregion
|
|
73
|
-
export type { GSwapErrorShape };
|
|
74
|
-
//# sourceMappingURL=wallet.d.ts.map
|
package/dist/wallet.mjs
DELETED
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
//#region src/utils/error_brand.ts
|
|
2
|
-
/**
|
|
3
|
-
* The brand every `GSwapSDKError` carries, and the duck-type check for the "failure shape". This
|
|
4
|
-
* module has NO imports on purpose: it is part of the light `@gala-chain/gswap-sdk/wallet` entry,
|
|
5
|
-
* which must never pull the error catalog or the main bundle in.
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* The brand of an SDK error: `error[GSWAP_ERROR_BRAND] === true`. It is a registered symbol
|
|
9
|
-
* (`Symbol.for`), so two copies of the SDK in one page (a wallet bundle and an app bundle) still
|
|
10
|
-
* recognise each other's errors, which `instanceof` cannot do.
|
|
11
|
-
*/
|
|
12
|
-
const GSWAP_ERROR_BRAND = Symbol.for("@gala-chain/gswap-sdk/error");
|
|
13
|
-
function isRecord$1(value) {
|
|
14
|
-
return typeof value === "object" && value !== null;
|
|
15
|
-
}
|
|
16
|
-
/** True when `value` carries the SDK error brand (a real `GSwapSDKError`, from any copy of the SDK). */
|
|
17
|
-
function hasGSwapErrorBrand(value) {
|
|
18
|
-
return isRecord$1(value) && value[GSWAP_ERROR_BRAND] === true;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* True when `value` is an SDK error (it carries the brand) or a plain-object VIEW of one: a string
|
|
22
|
-
* `code` and an object `params`, which is the shape of `GSwapSDKError` and of the wrapper objects
|
|
23
|
-
* an app builds from one (`{ code, params, status?, phase?, ... }`). A wallet's own error (an
|
|
24
|
-
* EIP-1193 numeric `code`, an ethers error with a string `code` and no `params`) is neither. It
|
|
25
|
-
* says the value has the SDK's shape, not that `code` is a code the SDK knows.
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* ```ts
|
|
29
|
-
* if (isGSwapErrorLike(error)) report(error.code, error.params); // no `instanceof`, no SDK import
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
function isGSwapErrorLike(value) {
|
|
33
|
-
if (hasGSwapErrorBrand(value)) return true;
|
|
34
|
-
return isRecord$1(value) && typeof value["code"] === "string" && isRecord$1(value["params"]) && !Array.isArray(value["params"]);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
//#endregion
|
|
38
|
-
//#region src/utils/wallet_rejection.ts
|
|
39
|
-
/**
|
|
40
|
-
* What the SDK knows about a failure thrown by a WALLET (the signer an app supplies, or wallet
|
|
41
|
-
* code of the app's own): the code the wallet put on it, and whether it means the person declined.
|
|
42
|
-
* Both read only the wallet's own error value; neither shows or forwards its text.
|
|
43
|
-
*/
|
|
44
|
-
/** Codes the EIP-1193 / ethers / viem families use for "the person declined in the wallet". */
|
|
45
|
-
const REJECTION_CODES = [
|
|
46
|
-
4001,
|
|
47
|
-
"ACTION_REJECTED",
|
|
48
|
-
"USER_REJECTED"
|
|
49
|
-
];
|
|
50
|
-
/** The `name` viem / wagmi give the error of a declined request. */
|
|
51
|
-
const REJECTION_NAME = "UserRejectedRequestError";
|
|
52
|
-
/**
|
|
53
|
-
* Wordings of a decline, matched case-insensitively as substrings. This is a LAST RESORT for
|
|
54
|
-
* wallets that set neither a `code` nor a `name`: it reads a third party's text, so it is broad on
|
|
55
|
-
* purpose (a superset of the matchers the Gala wallet and frontend_v2 used) and can in principle
|
|
56
|
-
* match an unrelated message that uses these words.
|
|
57
|
-
*/
|
|
58
|
-
const REJECTION_PHRASES = [
|
|
59
|
-
"user rejected",
|
|
60
|
-
"user denied",
|
|
61
|
-
"user cancel",
|
|
62
|
-
"rejected the request",
|
|
63
|
-
"request rejected",
|
|
64
|
-
"rejected by user",
|
|
65
|
-
"action_rejected",
|
|
66
|
-
"cancelled",
|
|
67
|
-
"canceled"
|
|
68
|
-
];
|
|
69
|
-
/** Properties wallets nest their text under (EIP-1193, ethers, viem, Gala wallet). */
|
|
70
|
-
const TEXT_KEYS = [
|
|
71
|
-
"message",
|
|
72
|
-
"Message",
|
|
73
|
-
"shortMessage",
|
|
74
|
-
"details",
|
|
75
|
-
"errorDetails",
|
|
76
|
-
"reason"
|
|
77
|
-
];
|
|
78
|
-
/** Wallet errors nest their text at most a level or two deep; the bound also stops a cyclic object. */
|
|
79
|
-
const MAX_TEXT_DEPTH = 3;
|
|
80
|
-
function isRecord(value) {
|
|
81
|
-
return typeof value === "object" && value !== null;
|
|
82
|
-
}
|
|
83
|
-
function textsOf(value, depth = 0) {
|
|
84
|
-
if (typeof value === "string") return [value];
|
|
85
|
-
if (!isRecord(value) || depth >= MAX_TEXT_DEPTH) return [];
|
|
86
|
-
return TEXT_KEYS.flatMap((key) => textsOf(value[key], depth + 1));
|
|
87
|
-
}
|
|
88
|
-
function wordsADecline(text) {
|
|
89
|
-
const lower = text.toLowerCase();
|
|
90
|
-
return REJECTION_PHRASES.some((phrase) => lower.includes(phrase)) || lower.includes("signature") && lower.includes("cancel");
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* True when a wallet's error (or just its message text) says the person DECLINED the request in
|
|
94
|
-
* their wallet. This is exactly the test behind `SIGNING_FAILED` with `params.reason ===
|
|
95
|
-
* 'user_rejected'`, exported for wallet code outside the SDK (connect and registration flows, a
|
|
96
|
-
* v1 write path) so an app keeps no matcher of its own.
|
|
97
|
-
*
|
|
98
|
-
* It is decided from the wallet's own fields first: a `code` of `4001` (EIP-1193), `'ACTION_REJECTED'`
|
|
99
|
-
* (ethers) or `'USER_REJECTED'`, or `name === 'UserRejectedRequestError'` (viem). Only when those are
|
|
100
|
-
* absent is the wallet's TEXT read (`message`, `Message`, `shortMessage`, `details`, `errorDetails`,
|
|
101
|
-
* `reason`, up to three levels deep, or a bare string): "user rejected", "user denied", "user
|
|
102
|
-
* cancelled", "request rejected", "rejected by user", "rejected the request", "cancelled" /
|
|
103
|
-
* "canceled", or a "signature ... cancel" sentence. The wording fallback is a last resort for
|
|
104
|
-
* wallets that do not set codes; prefer `code` and `name` wherever you control the wallet.
|
|
105
|
-
*
|
|
106
|
-
* An SDK error is never read by its text: a `SIGNING_FAILED` is a decline exactly when its
|
|
107
|
-
* `params.reason` is `user_rejected`, and every other SDK error is not one. The same holds for a
|
|
108
|
-
* plain-object VIEW of an SDK error (`{ code: 'SIGNING_FAILED', params: { reason } }`, the shape
|
|
109
|
-
* of an app's wrapper): a string `code` plus an object `params` is decided by the code alone, with
|
|
110
|
-
* the wallet code list above still honoured for a view that is not branded, and its English is
|
|
111
|
-
* never read. This works without `instanceof`, so it is safe across two copies of the SDK.
|
|
112
|
-
*
|
|
113
|
-
* @example
|
|
114
|
-
* ```ts
|
|
115
|
-
* try {
|
|
116
|
-
* await wallet.connect();
|
|
117
|
-
* } catch (error) {
|
|
118
|
-
* if (isWalletUserRejection(error)) return; // the person said no: not an error to report
|
|
119
|
-
* report(error);
|
|
120
|
-
* }
|
|
121
|
-
* ```
|
|
122
|
-
*/
|
|
123
|
-
function isWalletUserRejection(value) {
|
|
124
|
-
if (isGSwapErrorLike(value)) {
|
|
125
|
-
if (value.code === "SIGNING_FAILED") return value.params["reason"] === "user_rejected";
|
|
126
|
-
return !hasGSwapErrorBrand(value) && REJECTION_CODES.includes(value.code);
|
|
127
|
-
}
|
|
128
|
-
if (isRecord(value)) {
|
|
129
|
-
if (REJECTION_CODES.includes(value["code"]) || value["name"] === REJECTION_NAME) return true;
|
|
130
|
-
}
|
|
131
|
-
return textsOf(value).some(wordsADecline);
|
|
132
|
-
}
|
|
133
|
-
/** The longest wallet code kept: real ones (`4001`, `ACTION_REJECTED`) are short. */
|
|
134
|
-
const MAX_WALLET_CODE_LENGTH = 64;
|
|
135
|
-
/**
|
|
136
|
-
* The code a wallet put on its error: an EIP-1193 / JSON-RPC number (`4001`, `-32603`) or an
|
|
137
|
-
* ethers / viem string (`'ACTION_REJECTED'`), read from the error's own top-level `code`. Anything
|
|
138
|
-
* else (no code, a non-finite number, an empty or very long string, an object) is `undefined`, so
|
|
139
|
-
* the value is always a safe primitive. Used for `GSwapSDKError.walletCode`.
|
|
140
|
-
*
|
|
141
|
-
* @example
|
|
142
|
-
* ```ts
|
|
143
|
-
* walletDeclineCode({ code: 4001, message: 'User rejected the request.' }); // 4001
|
|
144
|
-
* walletDeclineCode(new Error('locked')); // undefined
|
|
145
|
-
* ```
|
|
146
|
-
*/
|
|
147
|
-
function walletDeclineCode(value) {
|
|
148
|
-
if (typeof value !== "object" || value === null) return void 0;
|
|
149
|
-
const { code } = value;
|
|
150
|
-
if (typeof code === "number") return Number.isFinite(code) ? code : void 0;
|
|
151
|
-
if (typeof code === "string" && code.length > 0 && code.length <= MAX_WALLET_CODE_LENGTH) return code;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
//#endregion
|
|
155
|
-
export { isGSwapErrorLike, isWalletUserRejection, walletDeclineCode };
|
|
156
|
-
//# sourceMappingURL=wallet.mjs.map
|
package/dist/wallet.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"wallet.mjs","names":["isRecord"],"sources":["../src/utils/error_brand.ts","../src/utils/wallet_rejection.ts"],"sourcesContent":["/**\n * The brand every `GSwapSDKError` carries, and the duck-type check for the \"failure shape\". This\n * module has NO imports on purpose: it is part of the light `@gala-chain/gswap-sdk/wallet` entry,\n * which must never pull the error catalog or the main bundle in.\n */\n\n/**\n * The brand of an SDK error: `error[GSWAP_ERROR_BRAND] === true`. It is a registered symbol\n * (`Symbol.for`), so two copies of the SDK in one page (a wallet bundle and an app bundle) still\n * recognise each other's errors, which `instanceof` cannot do.\n */\nexport const GSWAP_ERROR_BRAND: unique symbol = Symbol.for('@gala-chain/gswap-sdk/error');\n\n/** The least an object must have to be read as an SDK error or its plain-object view. */\nexport interface GSwapErrorShape {\n readonly code: string;\n readonly params: Readonly<Record<string, unknown>>;\n}\n\nfunction isRecord(value: unknown): value is Record<PropertyKey, unknown> {\n return typeof value === 'object' && value !== null;\n}\n\n/** True when `value` carries the SDK error brand (a real `GSwapSDKError`, from any copy of the SDK). */\nexport function hasGSwapErrorBrand(value: unknown): boolean {\n return isRecord(value) && value[GSWAP_ERROR_BRAND] === true;\n}\n\n/**\n * True when `value` is an SDK error (it carries the brand) or a plain-object VIEW of one: a string\n * `code` and an object `params`, which is the shape of `GSwapSDKError` and of the wrapper objects\n * an app builds from one (`{ code, params, status?, phase?, ... }`). A wallet's own error (an\n * EIP-1193 numeric `code`, an ethers error with a string `code` and no `params`) is neither. It\n * says the value has the SDK's shape, not that `code` is a code the SDK knows.\n *\n * @example\n * ```ts\n * if (isGSwapErrorLike(error)) report(error.code, error.params); // no `instanceof`, no SDK import\n * ```\n */\nexport function isGSwapErrorLike(value: unknown): value is GSwapErrorShape {\n if (hasGSwapErrorBrand(value)) return true;\n return (\n isRecord(value) &&\n typeof value['code'] === 'string' &&\n isRecord(value['params']) &&\n !Array.isArray(value['params'])\n );\n}\n","/**\n * What the SDK knows about a failure thrown by a WALLET (the signer an app supplies, or wallet\n * code of the app's own): the code the wallet put on it, and whether it means the person declined.\n * Both read only the wallet's own error value; neither shows or forwards its text.\n */\n\nimport { hasGSwapErrorBrand, isGSwapErrorLike } from './error_brand.js';\n\n// This module is the whole of the light `@gala-chain/gswap-sdk/wallet` entry (and the main entry\n// re-exports it, so there is one implementation). It must stay dependency-free: it may import\n// only `./error_brand.js`, never the error catalog, `GSwapSDKError` or the main index.\n\n/** Codes the EIP-1193 / ethers / viem families use for \"the person declined in the wallet\". */\nconst REJECTION_CODES: readonly unknown[] = [4001, 'ACTION_REJECTED', 'USER_REJECTED'];\n\n/** The `name` viem / wagmi give the error of a declined request. */\nconst REJECTION_NAME = 'UserRejectedRequestError';\n\n/**\n * Wordings of a decline, matched case-insensitively as substrings. This is a LAST RESORT for\n * wallets that set neither a `code` nor a `name`: it reads a third party's text, so it is broad on\n * purpose (a superset of the matchers the Gala wallet and frontend_v2 used) and can in principle\n * match an unrelated message that uses these words.\n */\nconst REJECTION_PHRASES: readonly string[] = [\n 'user rejected',\n 'user denied',\n 'user cancel',\n 'rejected the request',\n 'request rejected',\n 'rejected by user',\n 'action_rejected',\n 'cancelled',\n 'canceled',\n];\n\n/** Properties wallets nest their text under (EIP-1193, ethers, viem, Gala wallet). */\nconst TEXT_KEYS: readonly string[] = [\n 'message',\n 'Message',\n 'shortMessage',\n 'details',\n 'errorDetails',\n 'reason',\n];\n\n/** Wallet errors nest their text at most a level or two deep; the bound also stops a cyclic object. */\nconst MAX_TEXT_DEPTH = 3;\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null;\n}\n\nfunction textsOf(value: unknown, depth = 0): string[] {\n if (typeof value === 'string') return [value];\n if (!isRecord(value) || depth >= MAX_TEXT_DEPTH) return [];\n return TEXT_KEYS.flatMap((key) => textsOf(value[key], depth + 1));\n}\n\nfunction wordsADecline(text: string): boolean {\n const lower = text.toLowerCase();\n return (\n REJECTION_PHRASES.some((phrase) => lower.includes(phrase)) ||\n (lower.includes('signature') && lower.includes('cancel'))\n );\n}\n\n/**\n * True when a wallet's error (or just its message text) says the person DECLINED the request in\n * their wallet. This is exactly the test behind `SIGNING_FAILED` with `params.reason ===\n * 'user_rejected'`, exported for wallet code outside the SDK (connect and registration flows, a\n * v1 write path) so an app keeps no matcher of its own.\n *\n * It is decided from the wallet's own fields first: a `code` of `4001` (EIP-1193), `'ACTION_REJECTED'`\n * (ethers) or `'USER_REJECTED'`, or `name === 'UserRejectedRequestError'` (viem). Only when those are\n * absent is the wallet's TEXT read (`message`, `Message`, `shortMessage`, `details`, `errorDetails`,\n * `reason`, up to three levels deep, or a bare string): \"user rejected\", \"user denied\", \"user\n * cancelled\", \"request rejected\", \"rejected by user\", \"rejected the request\", \"cancelled\" /\n * \"canceled\", or a \"signature ... cancel\" sentence. The wording fallback is a last resort for\n * wallets that do not set codes; prefer `code` and `name` wherever you control the wallet.\n *\n * An SDK error is never read by its text: a `SIGNING_FAILED` is a decline exactly when its\n * `params.reason` is `user_rejected`, and every other SDK error is not one. The same holds for a\n * plain-object VIEW of an SDK error (`{ code: 'SIGNING_FAILED', params: { reason } }`, the shape\n * of an app's wrapper): a string `code` plus an object `params` is decided by the code alone, with\n * the wallet code list above still honoured for a view that is not branded, and its English is\n * never read. This works without `instanceof`, so it is safe across two copies of the SDK.\n *\n * @example\n * ```ts\n * try {\n * await wallet.connect();\n * } catch (error) {\n * if (isWalletUserRejection(error)) return; // the person said no: not an error to report\n * report(error);\n * }\n * ```\n */\nexport function isWalletUserRejection(value: unknown): boolean {\n if (isGSwapErrorLike(value)) {\n if (value.code === 'SIGNING_FAILED') return value.params['reason'] === 'user_rejected';\n return !hasGSwapErrorBrand(value) && REJECTION_CODES.includes(value.code);\n }\n if (isRecord(value)) {\n if (REJECTION_CODES.includes(value['code']) || value['name'] === REJECTION_NAME) return true;\n }\n return textsOf(value).some(wordsADecline);\n}\n\n/** The longest wallet code kept: real ones (`4001`, `ACTION_REJECTED`) are short. */\nconst MAX_WALLET_CODE_LENGTH = 64;\n\n/**\n * The code a wallet put on its error: an EIP-1193 / JSON-RPC number (`4001`, `-32603`) or an\n * ethers / viem string (`'ACTION_REJECTED'`), read from the error's own top-level `code`. Anything\n * else (no code, a non-finite number, an empty or very long string, an object) is `undefined`, so\n * the value is always a safe primitive. Used for `GSwapSDKError.walletCode`.\n *\n * @example\n * ```ts\n * walletDeclineCode({ code: 4001, message: 'User rejected the request.' }); // 4001\n * walletDeclineCode(new Error('locked')); // undefined\n * ```\n */\nexport function walletDeclineCode(value: unknown): number | string | undefined {\n if (typeof value !== 'object' || value === null) return undefined;\n const { code } = value as { code?: unknown };\n if (typeof code === 'number') return Number.isFinite(code) ? code : undefined;\n if (typeof code === 'string' && code.length > 0 && code.length <= MAX_WALLET_CODE_LENGTH) {\n return code;\n }\n return undefined;\n}\n"],"mappings":";;;;;;;;;;;AAWA,MAAa,oBAAmC,OAAO,IAAI,6BAA6B;AAQxF,SAASA,WAAS,OAAuD;CACvE,OAAO,OAAO,UAAU,YAAY,UAAU;AAChD;;AAGA,SAAgB,mBAAmB,OAAyB;CAC1D,OAAOA,WAAS,KAAK,KAAK,MAAM,uBAAuB;AACzD;;;;;;;;;;;;;AAcA,SAAgB,iBAAiB,OAA0C;CACzE,IAAI,mBAAmB,KAAK,GAAG,OAAO;CACtC,OACEA,WAAS,KAAK,KACd,OAAO,MAAM,YAAY,YACzBA,WAAS,MAAM,SAAS,KACxB,CAAC,MAAM,QAAQ,MAAM,SAAS;AAElC;;;;;;;;;;ACnCA,MAAM,kBAAsC;CAAC;CAAM;CAAmB;AAAe;;AAGrF,MAAM,iBAAiB;;;;;;;AAQvB,MAAM,oBAAuC;CAC3C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;AAGA,MAAM,YAA+B;CACnC;CACA;CACA;CACA;CACA;CACA;AACF;;AAGA,MAAM,iBAAiB;AAEvB,SAAS,SAAS,OAAkD;CAClE,OAAO,OAAO,UAAU,YAAY,UAAU;AAChD;AAEA,SAAS,QAAQ,OAAgB,QAAQ,GAAa;CACpD,IAAI,OAAO,UAAU,UAAU,OAAO,CAAC,KAAK;CAC5C,IAAI,CAAC,SAAS,KAAK,KAAK,SAAS,gBAAgB,OAAO,CAAC;CACzD,OAAO,UAAU,SAAS,QAAQ,QAAQ,MAAM,MAAM,QAAQ,CAAC,CAAC;AAClE;AAEA,SAAS,cAAc,MAAuB;CAC5C,MAAM,QAAQ,KAAK,YAAY;CAC/B,OACE,kBAAkB,MAAM,WAAW,MAAM,SAAS,MAAM,CAAC,KACxD,MAAM,SAAS,WAAW,KAAK,MAAM,SAAS,QAAQ;AAE3D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,SAAgB,sBAAsB,OAAyB;CAC7D,IAAI,iBAAiB,KAAK,GAAG;EAC3B,IAAI,MAAM,SAAS,kBAAkB,OAAO,MAAM,OAAO,cAAc;EACvE,OAAO,CAAC,mBAAmB,KAAK,KAAK,gBAAgB,SAAS,MAAM,IAAI;CAC1E;CACA,IAAI,SAAS,KAAK,GAChB;MAAI,gBAAgB,SAAS,MAAM,OAAO,KAAK,MAAM,YAAY,gBAAgB,OAAO;CAAI;CAE9F,OAAO,QAAQ,KAAK,CAAC,CAAC,KAAK,aAAa;AAC1C;;AAGA,MAAM,yBAAyB;;;;;;;;;;;;;AAc/B,SAAgB,kBAAkB,OAA6C;CAC7E,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,OAAO;CACxD,MAAM,EAAE,SAAS;CACjB,IAAI,OAAO,SAAS,UAAU,OAAO,OAAO,SAAS,IAAI,IAAI,OAAO;CACpE,IAAI,OAAO,SAAS,YAAY,KAAK,SAAS,KAAK,KAAK,UAAU,wBAChE,OAAO;AAGX"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|