@relayprotocol/relay-kit-ui 7.0.11 → 7.1.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/_cjs/src/components/widgets/SwapWidgetRenderer.js +4 -5
- package/_cjs/src/components/widgets/SwapWidgetRenderer.js.map +1 -1
- package/_cjs/src/components/widgets/TokenWidget/widget/TokenWidgetRenderer.js +4 -5
- package/_cjs/src/components/widgets/TokenWidget/widget/TokenWidgetRenderer.js.map +1 -1
- package/_cjs/src/hooks/index.js +3 -3
- package/_cjs/src/hooks/index.js.map +1 -1
- package/_cjs/src/hooks/useExplicitDeposit.js +52 -0
- package/_cjs/src/hooks/useExplicitDeposit.js.map +1 -0
- package/_cjs/src/version.js +1 -1
- package/_cjs/src/version.js.map +1 -1
- package/_cjs/tsconfig.build.tsbuildinfo +1 -1
- package/_esm/src/components/widgets/SwapWidgetRenderer.js +5 -6
- package/_esm/src/components/widgets/SwapWidgetRenderer.js.map +1 -1
- package/_esm/src/components/widgets/TokenWidget/widget/TokenWidgetRenderer.js +5 -6
- package/_esm/src/components/widgets/TokenWidget/widget/TokenWidgetRenderer.js.map +1 -1
- package/_esm/src/hooks/index.js +2 -2
- package/_esm/src/hooks/index.js.map +1 -1
- package/_esm/src/hooks/useExplicitDeposit.js +63 -0
- package/_esm/src/hooks/useExplicitDeposit.js.map +1 -0
- package/_esm/src/version.js +1 -1
- package/_esm/src/version.js.map +1 -1
- package/_esm/tsconfig.build.tsbuildinfo +1 -1
- package/_types/src/components/widgets/SwapWidgetRenderer.d.ts.map +1 -1
- package/_types/src/components/widgets/TokenWidget/widget/TokenWidgetRenderer.d.ts.map +1 -1
- package/_types/src/hooks/index.d.ts +2 -2
- package/_types/src/hooks/index.d.ts.map +1 -1
- package/_types/src/hooks/useExplicitDeposit.d.ts +10 -0
- package/_types/src/hooks/useExplicitDeposit.d.ts.map +1 -0
- package/_types/src/version.d.ts +1 -1
- package/_types/src/version.d.ts.map +1 -1
- package/_types/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/_cjs/src/hooks/useEOADetection.js +0 -156
- package/_cjs/src/hooks/useEOADetection.js.map +0 -1
- package/_esm/src/hooks/useEOADetection.js +0 -163
- package/_esm/src/hooks/useEOADetection.js.map +0 -1
- package/_types/src/hooks/useEOADetection.d.ts +0 -9
- package/_types/src/hooks/useEOADetection.d.ts.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@relayprotocol/relay-kit-ui",
|
|
3
|
-
"version": "7.0
|
|
3
|
+
"version": "7.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./_cjs/src/index.js",
|
|
6
6
|
"module": "./_esm/src/index.js",
|
|
@@ -85,8 +85,8 @@
|
|
|
85
85
|
"qrcode.react": "^4.1.0",
|
|
86
86
|
"usehooks-ts": "^3.1.0",
|
|
87
87
|
"@relayprotocol/relay-design-system": "^1.0.0",
|
|
88
|
-
"@relayprotocol/relay-kit-hooks": "3.0.
|
|
89
|
-
"@relayprotocol/relay-sdk": "5.0
|
|
88
|
+
"@relayprotocol/relay-kit-hooks": "3.0.6",
|
|
89
|
+
"@relayprotocol/relay-sdk": "5.1.0"
|
|
90
90
|
},
|
|
91
91
|
"keywords": [
|
|
92
92
|
"eth",
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
const react_1 = require("react");
|
|
5
|
-
const useCurrencyBalance_js_1 = tslib_1.__importDefault(require("./useCurrencyBalance.js"));
|
|
6
|
-
const useTransactionCount_js_1 = tslib_1.__importDefault(require("./useTransactionCount.js"));
|
|
7
|
-
const useEOADetection = (wallet, chainId, chainVmType, fromChain, userAddress, fromBalance, isFromNative) => {
|
|
8
|
-
const [detectionState, setDetectionState] = (0, react_1.useState)({ value: undefined, conditionKey: '' });
|
|
9
|
-
const walletRef = (0, react_1.useRef)(wallet);
|
|
10
|
-
const walletId = (0, react_1.useRef)(0);
|
|
11
|
-
if (walletRef.current !== wallet) {
|
|
12
|
-
walletRef.current = wallet;
|
|
13
|
-
walletId.current += 1;
|
|
14
|
-
}
|
|
15
|
-
const shouldRunSafetyChecks = Boolean(chainVmType === 'evm' && !isFromNative && userAddress && fromChain);
|
|
16
|
-
const { value: nativeBalance, isLoading: isLoadingNativeBalance } = (0, useCurrencyBalance_js_1.default)({
|
|
17
|
-
chain: fromChain,
|
|
18
|
-
address: userAddress,
|
|
19
|
-
currency: fromChain?.currency?.address
|
|
20
|
-
? fromChain.currency.address
|
|
21
|
-
: undefined,
|
|
22
|
-
enabled: shouldRunSafetyChecks,
|
|
23
|
-
wallet
|
|
24
|
-
});
|
|
25
|
-
const { data: transactionCount, isLoading: isLoadingTransactionCount } = (0, useTransactionCount_js_1.default)({
|
|
26
|
-
address: userAddress,
|
|
27
|
-
chainId: chainId,
|
|
28
|
-
enabled: shouldRunSafetyChecks
|
|
29
|
-
});
|
|
30
|
-
const isLoadingSafetyChecks = Boolean(shouldRunSafetyChecks &&
|
|
31
|
-
(isLoadingNativeBalance || isLoadingTransactionCount));
|
|
32
|
-
const effectiveNativeBalance = isFromNative ? fromBalance : nativeBalance;
|
|
33
|
-
const hasZeroNativeBalance = shouldRunSafetyChecks && effectiveNativeBalance === 0n;
|
|
34
|
-
const hasLowTransactionCount = shouldRunSafetyChecks &&
|
|
35
|
-
transactionCount !== undefined &&
|
|
36
|
-
transactionCount <= 1;
|
|
37
|
-
const conditionKey = `${wallet?.vmType}:${chainVmType}:${!!wallet?.isEOA}:${chainId}:${walletId.current}:${hasZeroNativeBalance}:${hasLowTransactionCount}`;
|
|
38
|
-
const shouldDetect = (0, react_1.useMemo)(() => {
|
|
39
|
-
return (chainId !== undefined &&
|
|
40
|
-
(!wallet || wallet?.vmType === 'evm') &&
|
|
41
|
-
chainVmType === 'evm' &&
|
|
42
|
-
!hasZeroNativeBalance &&
|
|
43
|
-
!hasLowTransactionCount);
|
|
44
|
-
}, [
|
|
45
|
-
wallet?.vmType,
|
|
46
|
-
chainId,
|
|
47
|
-
chainVmType,
|
|
48
|
-
hasZeroNativeBalance,
|
|
49
|
-
hasLowTransactionCount
|
|
50
|
-
]);
|
|
51
|
-
const explicitDeposit = (0, react_1.useMemo)(() => {
|
|
52
|
-
if (isLoadingSafetyChecks) {
|
|
53
|
-
return undefined;
|
|
54
|
-
}
|
|
55
|
-
if (hasZeroNativeBalance || hasLowTransactionCount) {
|
|
56
|
-
return true;
|
|
57
|
-
}
|
|
58
|
-
return detectionState.conditionKey !== conditionKey || !shouldDetect
|
|
59
|
-
? undefined
|
|
60
|
-
: detectionState.value;
|
|
61
|
-
}, [
|
|
62
|
-
conditionKey,
|
|
63
|
-
shouldDetect,
|
|
64
|
-
detectionState,
|
|
65
|
-
hasZeroNativeBalance,
|
|
66
|
-
hasLowTransactionCount,
|
|
67
|
-
isLoadingSafetyChecks
|
|
68
|
-
]);
|
|
69
|
-
(0, react_1.useEffect)(() => {
|
|
70
|
-
setDetectionState({ value: undefined, conditionKey });
|
|
71
|
-
if (!shouldDetect) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
const detectEOA = async () => {
|
|
75
|
-
const baseEventData = {
|
|
76
|
-
chain_id: chainId,
|
|
77
|
-
address: userAddress,
|
|
78
|
-
wallet_type: wallet?.vmType
|
|
79
|
-
};
|
|
80
|
-
try {
|
|
81
|
-
if (!wallet || !wallet?.isEOA) {
|
|
82
|
-
setDetectionState((current) => current.conditionKey === conditionKey
|
|
83
|
-
? { value: false, conditionKey }
|
|
84
|
-
: current);
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
const timeoutMs = 2500;
|
|
88
|
-
const timeoutError = new Error('EOA_DETECTION_TIMEOUT');
|
|
89
|
-
let timeoutId;
|
|
90
|
-
const startTime = performance.now();
|
|
91
|
-
try {
|
|
92
|
-
const eoaResult = await Promise.race([
|
|
93
|
-
wallet.isEOA(chainId),
|
|
94
|
-
new Promise((_, reject) => {
|
|
95
|
-
timeoutId = setTimeout(() => {
|
|
96
|
-
reject(timeoutError);
|
|
97
|
-
}, timeoutMs);
|
|
98
|
-
})
|
|
99
|
-
]);
|
|
100
|
-
if (timeoutId) {
|
|
101
|
-
clearTimeout(timeoutId);
|
|
102
|
-
}
|
|
103
|
-
const { isEOA, isEIP7702Delegated } = eoaResult;
|
|
104
|
-
const explicitDepositValue = !isEOA || isEIP7702Delegated;
|
|
105
|
-
setDetectionState((current) => current.conditionKey === conditionKey
|
|
106
|
-
? { value: explicitDepositValue, conditionKey }
|
|
107
|
-
: current);
|
|
108
|
-
}
|
|
109
|
-
catch (eoaError) {
|
|
110
|
-
if (timeoutId) {
|
|
111
|
-
clearTimeout(timeoutId);
|
|
112
|
-
}
|
|
113
|
-
const duration = performance.now() - startTime;
|
|
114
|
-
const isTimeout = eoaError === timeoutError;
|
|
115
|
-
if (isTimeout) {
|
|
116
|
-
console.error('[EOA Detection] timeout', {
|
|
117
|
-
...baseEventData,
|
|
118
|
-
error_type: 'timeout',
|
|
119
|
-
duration_ms: Math.round(duration)
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
console.error('[EOA Detection] error', {
|
|
124
|
-
...baseEventData,
|
|
125
|
-
error_type: 'error',
|
|
126
|
-
duration_ms: Math.round(duration),
|
|
127
|
-
error_message: eoaError?.message || 'Unknown error',
|
|
128
|
-
error_name: eoaError?.name
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
setDetectionState((current) => current.conditionKey === conditionKey
|
|
132
|
-
? { value: true, conditionKey }
|
|
133
|
-
: current);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
catch (error) {
|
|
137
|
-
console.error('[EOA Detection] error', {
|
|
138
|
-
...baseEventData,
|
|
139
|
-
error_type: 'error',
|
|
140
|
-
error_message: error?.message || 'Unknown error',
|
|
141
|
-
error_name: error?.name
|
|
142
|
-
});
|
|
143
|
-
setDetectionState((current) => current.conditionKey === conditionKey
|
|
144
|
-
? { value: true, conditionKey }
|
|
145
|
-
: current);
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
detectEOA();
|
|
149
|
-
}, [conditionKey, shouldDetect, wallet, chainId, userAddress]);
|
|
150
|
-
if (!shouldDetect && chainVmType === 'evm') {
|
|
151
|
-
return explicitDeposit ?? true;
|
|
152
|
-
}
|
|
153
|
-
return explicitDeposit;
|
|
154
|
-
};
|
|
155
|
-
exports.default = useEOADetection;
|
|
156
|
-
//# sourceMappingURL=useEOADetection.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useEOADetection.js","sourceRoot":"","sources":["../../../src/hooks/useEOADetection.ts"],"names":[],"mappings":";;;AAAA,iCAA4D;AAE5D,4FAAwD;AACxD,8FAA0D;AAO1D,MAAM,eAAe,GAAG,CACtB,MAAsB,EACtB,OAAgB,EAChB,WAAoB,EACpB,SAAsB,EACtB,WAAoB,EACpB,WAAoB,EACpB,YAAsB,EACD,EAAE;IACvB,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAG,IAAA,gBAAQ,EAGjD,EAAE,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,CAAA;IAE1C,MAAM,SAAS,GAAG,IAAA,cAAM,EAA4B,MAAM,CAAC,CAAA;IAC3D,MAAM,QAAQ,GAAG,IAAA,cAAM,EAAS,CAAC,CAAC,CAAA;IAElC,IAAI,SAAS,CAAC,OAAO,KAAK,MAAM,EAAE,CAAC;QACjC,SAAS,CAAC,OAAO,GAAG,MAAM,CAAA;QAC1B,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAA;IACvB,CAAC;IAED,MAAM,qBAAqB,GAAG,OAAO,CACnC,WAAW,KAAK,KAAK,IAAI,CAAC,YAAY,IAAI,WAAW,IAAI,SAAS,CACnE,CAAA;IAGD,MAAM,EAAE,K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,IAAI,CAAA;IAChC,CAAC;IAED,OAAO,eAAe,CAAA;AACxB,CAAC,CAAA;AAED,kBAAe,eAAe,CAAA"}
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import { useMemo, useEffect, useState, useRef } from 'react';
|
|
2
|
-
import useCurrencyBalance from './useCurrencyBalance.js';
|
|
3
|
-
import useTransactionCount from './useTransactionCount.js';
|
|
4
|
-
/**
|
|
5
|
-
* Hook to detect if a wallet is an EOA and return the appropriate explicitDeposit flag
|
|
6
|
-
* Includes checks for zero native balance and low transaction count
|
|
7
|
-
* Only runs detection when evm chain and wallet supports EOA detection
|
|
8
|
-
*/
|
|
9
|
-
const useEOADetection = (wallet, chainId, chainVmType, fromChain, userAddress, fromBalance, isFromNative) => {
|
|
10
|
-
const [detectionState, setDetectionState] = useState({ value: undefined, conditionKey: '' });
|
|
11
|
-
const walletRef = useRef(wallet);
|
|
12
|
-
const walletId = useRef(0);
|
|
13
|
-
if (walletRef.current !== wallet) {
|
|
14
|
-
walletRef.current = wallet;
|
|
15
|
-
walletId.current += 1;
|
|
16
|
-
}
|
|
17
|
-
const shouldRunSafetyChecks = Boolean(chainVmType === 'evm' && !isFromNative && userAddress && fromChain);
|
|
18
|
-
// get native balance
|
|
19
|
-
const { value: nativeBalance, isLoading: isLoadingNativeBalance } = useCurrencyBalance({
|
|
20
|
-
chain: fromChain,
|
|
21
|
-
address: userAddress,
|
|
22
|
-
currency: fromChain?.currency?.address
|
|
23
|
-
? fromChain.currency.address
|
|
24
|
-
: undefined,
|
|
25
|
-
enabled: shouldRunSafetyChecks,
|
|
26
|
-
wallet
|
|
27
|
-
});
|
|
28
|
-
// get transaction count
|
|
29
|
-
const { data: transactionCount, isLoading: isLoadingTransactionCount } = useTransactionCount({
|
|
30
|
-
address: userAddress,
|
|
31
|
-
chainId: chainId,
|
|
32
|
-
enabled: shouldRunSafetyChecks
|
|
33
|
-
});
|
|
34
|
-
const isLoadingSafetyChecks = Boolean(shouldRunSafetyChecks &&
|
|
35
|
-
(isLoadingNativeBalance || isLoadingTransactionCount));
|
|
36
|
-
// Calculate safety check conditions
|
|
37
|
-
const effectiveNativeBalance = isFromNative ? fromBalance : nativeBalance;
|
|
38
|
-
const hasZeroNativeBalance = shouldRunSafetyChecks && effectiveNativeBalance === 0n;
|
|
39
|
-
const hasLowTransactionCount = shouldRunSafetyChecks &&
|
|
40
|
-
transactionCount !== undefined &&
|
|
41
|
-
transactionCount <= 1;
|
|
42
|
-
const conditionKey = `${wallet?.vmType}:${chainVmType}:${!!wallet?.isEOA}:${chainId}:${walletId.current}:${hasZeroNativeBalance}:${hasLowTransactionCount}`;
|
|
43
|
-
const shouldDetect = useMemo(() => {
|
|
44
|
-
return (chainId !== undefined &&
|
|
45
|
-
(!wallet || wallet?.vmType === 'evm') &&
|
|
46
|
-
chainVmType === 'evm' &&
|
|
47
|
-
!hasZeroNativeBalance &&
|
|
48
|
-
!hasLowTransactionCount);
|
|
49
|
-
}, [
|
|
50
|
-
wallet?.vmType,
|
|
51
|
-
chainId,
|
|
52
|
-
chainVmType,
|
|
53
|
-
hasZeroNativeBalance,
|
|
54
|
-
hasLowTransactionCount
|
|
55
|
-
]);
|
|
56
|
-
// Synchronously return undefined when conditions change
|
|
57
|
-
const explicitDeposit = useMemo(() => {
|
|
58
|
-
if (isLoadingSafetyChecks) {
|
|
59
|
-
return undefined;
|
|
60
|
-
}
|
|
61
|
-
// force explicit deposit for zero native balance or low transaction count
|
|
62
|
-
if (hasZeroNativeBalance || hasLowTransactionCount) {
|
|
63
|
-
return true;
|
|
64
|
-
}
|
|
65
|
-
return detectionState.conditionKey !== conditionKey || !shouldDetect
|
|
66
|
-
? undefined
|
|
67
|
-
: detectionState.value;
|
|
68
|
-
}, [
|
|
69
|
-
conditionKey,
|
|
70
|
-
shouldDetect,
|
|
71
|
-
detectionState,
|
|
72
|
-
hasZeroNativeBalance,
|
|
73
|
-
hasLowTransactionCount,
|
|
74
|
-
isLoadingSafetyChecks
|
|
75
|
-
]);
|
|
76
|
-
useEffect(() => {
|
|
77
|
-
setDetectionState({ value: undefined, conditionKey });
|
|
78
|
-
if (!shouldDetect) {
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
const detectEOA = async () => {
|
|
82
|
-
const baseEventData = {
|
|
83
|
-
chain_id: chainId,
|
|
84
|
-
address: userAddress,
|
|
85
|
-
wallet_type: wallet?.vmType
|
|
86
|
-
};
|
|
87
|
-
try {
|
|
88
|
-
if (!wallet || !wallet?.isEOA) {
|
|
89
|
-
setDetectionState((current) => current.conditionKey === conditionKey
|
|
90
|
-
? { value: false, conditionKey }
|
|
91
|
-
: current);
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
const timeoutMs = 2500;
|
|
95
|
-
const timeoutError = new Error('EOA_DETECTION_TIMEOUT');
|
|
96
|
-
let timeoutId;
|
|
97
|
-
const startTime = performance.now();
|
|
98
|
-
try {
|
|
99
|
-
const eoaResult = await Promise.race([
|
|
100
|
-
wallet.isEOA(chainId),
|
|
101
|
-
new Promise((_, reject) => {
|
|
102
|
-
timeoutId = setTimeout(() => {
|
|
103
|
-
reject(timeoutError);
|
|
104
|
-
}, timeoutMs);
|
|
105
|
-
})
|
|
106
|
-
]);
|
|
107
|
-
if (timeoutId) {
|
|
108
|
-
clearTimeout(timeoutId);
|
|
109
|
-
}
|
|
110
|
-
const { isEOA, isEIP7702Delegated } = eoaResult;
|
|
111
|
-
const explicitDepositValue = !isEOA || isEIP7702Delegated;
|
|
112
|
-
setDetectionState((current) => current.conditionKey === conditionKey
|
|
113
|
-
? { value: explicitDepositValue, conditionKey }
|
|
114
|
-
: current);
|
|
115
|
-
}
|
|
116
|
-
catch (eoaError) {
|
|
117
|
-
if (timeoutId) {
|
|
118
|
-
clearTimeout(timeoutId);
|
|
119
|
-
}
|
|
120
|
-
const duration = performance.now() - startTime;
|
|
121
|
-
const isTimeout = eoaError === timeoutError;
|
|
122
|
-
if (isTimeout) {
|
|
123
|
-
console.error('[EOA Detection] timeout', {
|
|
124
|
-
...baseEventData,
|
|
125
|
-
error_type: 'timeout',
|
|
126
|
-
duration_ms: Math.round(duration)
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
console.error('[EOA Detection] error', {
|
|
131
|
-
...baseEventData,
|
|
132
|
-
error_type: 'error',
|
|
133
|
-
duration_ms: Math.round(duration),
|
|
134
|
-
error_message: eoaError?.message || 'Unknown error',
|
|
135
|
-
error_name: eoaError?.name
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
setDetectionState((current) => current.conditionKey === conditionKey
|
|
139
|
-
? { value: true, conditionKey }
|
|
140
|
-
: current);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
catch (error) {
|
|
144
|
-
console.error('[EOA Detection] error', {
|
|
145
|
-
...baseEventData,
|
|
146
|
-
error_type: 'error',
|
|
147
|
-
error_message: error?.message || 'Unknown error',
|
|
148
|
-
error_name: error?.name
|
|
149
|
-
});
|
|
150
|
-
setDetectionState((current) => current.conditionKey === conditionKey
|
|
151
|
-
? { value: true, conditionKey }
|
|
152
|
-
: current);
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
detectEOA();
|
|
156
|
-
}, [conditionKey, shouldDetect, wallet, chainId, userAddress]);
|
|
157
|
-
if (!shouldDetect && chainVmType === 'evm') {
|
|
158
|
-
return explicitDeposit ?? true;
|
|
159
|
-
}
|
|
160
|
-
return explicitDeposit;
|
|
161
|
-
};
|
|
162
|
-
export default useEOADetection;
|
|
163
|
-
//# sourceMappingURL=useEOADetection.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useEOADetection.js","sourceRoot":"","sources":["../../../src/hooks/useEOADetection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AAE5D,OAAO,kBAAkB,MAAM,yBAAyB,CAAA;AACxD,OAAO,mB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K,EAAE,IAAI,EAAE,YAAY,EAAE;wBAC/B,CAAC,CAAC,OAAO,CACZ,CAAA;gBACH,CAAC;YACH,CAAC;YAAC,OAAO,KAAU,EAAE,CAAC;gBACpB,OAAO,CAAC,KAAK,CAAC,uBAAuB,EAAE;oBACrC,GAAG,aAAa;oBAChB,UAAU,EAAE,OAAO;oBACnB,aAAa,EAAE,KAAK,EAAE,OAAO,IAAI,eAAe;oBAChD,UAAU,EAAE,KAAK,EAAE,IAAI;iBACxB,CAAC,CAAA;gBAEF,iBAAiB,CAAC,CAAC,OAAO,EAAE,EAAE,CAC5B,OAAO,CAAC,YAAY,KAAK,YAAY;oBACnC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE;oBAC/B,CAAC,CAAC,OAAO,CACZ,CAAA;YACH,CAAC;QACH,CAAC,CAAA;QAED,SAAS,EAAE,CAAA;IACb,CAAC,EAAE,CAAC,YAAY,EAAE,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC,CAAA;IAE9D,IAAI,CAAC,YAAY,IAAI,WAAW,KAAK,KAAK,EAAE,CAAC;QAC3C,OAAO,eAAe,IAAI,IAAI,CAAA;IAChC,CAAC;IAED,OAAO,eAAe,CAAA;AACxB,CAAC,CAAA;AAED,eAAe,eAAe,CAAA"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { AdaptedWallet, RelayChain } from '@relayprotocol/relay-sdk';
|
|
2
|
-
/**
|
|
3
|
-
* Hook to detect if a wallet is an EOA and return the appropriate explicitDeposit flag
|
|
4
|
-
* Includes checks for zero native balance and low transaction count
|
|
5
|
-
* Only runs detection when evm chain and wallet supports EOA detection
|
|
6
|
-
*/
|
|
7
|
-
declare const useEOADetection: (wallet?: AdaptedWallet, chainId?: number, chainVmType?: string, fromChain?: RelayChain, userAddress?: string, fromBalance?: bigint, isFromNative?: boolean) => boolean | undefined;
|
|
8
|
-
export default useEOADetection;
|
|
9
|
-
//# sourceMappingURL=useEOADetection.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useEOADetection.d.ts","sourceRoot":"","sources":["../../../src/hooks/useEOADetection.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAIzE;;;;GAIG;AACH,QAAA,MAAM,eAAe,YACV,aAAa,YACZ,MAAM,gBACF,MAAM,cACR,UAAU,gBACR,MAAM,gBACN,MAAM,iBACL,OAAO,KACrB,OAAO,GAAG,SAqMZ,CAAA;AAED,eAAe,eAAe,CAAA"}
|