@coti-io/coti-wallet-plugin 0.2.1 → 0.2.2
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/dist/index.d.mts +14 -7
- package/dist/index.d.ts +14 -7
- package/dist/index.js +63 -28
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +62 -27
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -1
package/dist/index.mjs
CHANGED
|
@@ -546,10 +546,10 @@ function configureCotiPlugin(config) {
|
|
|
546
546
|
...config.onboardingServices
|
|
547
547
|
}
|
|
548
548
|
};
|
|
549
|
-
if ("
|
|
550
|
-
console.log("[CotiPlugin]
|
|
551
|
-
|
|
552
|
-
effective:
|
|
549
|
+
if ("snapEnabled" in config && _config.debug) {
|
|
550
|
+
console.log("[CotiPlugin] snapEnabled:", {
|
|
551
|
+
snapEnabled: config.snapEnabled,
|
|
552
|
+
effective: isSnapEnabled()
|
|
553
553
|
});
|
|
554
554
|
}
|
|
555
555
|
}
|
|
@@ -560,8 +560,8 @@ function getSnapRequestParams(snapId = _config.snapId, snapVersion) {
|
|
|
560
560
|
function getPluginConfig() {
|
|
561
561
|
return _config;
|
|
562
562
|
}
|
|
563
|
-
function
|
|
564
|
-
return getPluginConfig().
|
|
563
|
+
function isSnapEnabled() {
|
|
564
|
+
return getPluginConfig().snapEnabled !== false;
|
|
565
565
|
}
|
|
566
566
|
var _config;
|
|
567
567
|
var init_plugin = __esm({
|
|
@@ -570,7 +570,7 @@ var init_plugin = __esm({
|
|
|
570
570
|
init_chains();
|
|
571
571
|
_config = {
|
|
572
572
|
snapId: "npm:@coti-io/coti-snap",
|
|
573
|
-
|
|
573
|
+
snapEnabled: true,
|
|
574
574
|
defaultNetworkId: void 0,
|
|
575
575
|
debug: false,
|
|
576
576
|
clearSessionKeyOnWagmiDisconnect: false,
|
|
@@ -1400,6 +1400,7 @@ var resolveBridgeAddress = (chainId, symbol, pubTok) => {
|
|
|
1400
1400
|
if (symbol === "USDC.e") return addresses.PrivacyBridgeUSDCe;
|
|
1401
1401
|
if (symbol === "WADA") return addresses.PrivacyBridgeWADA;
|
|
1402
1402
|
if (symbol === "gCOTI") return addresses.PrivacyBridgegCOTI;
|
|
1403
|
+
if (symbol === "NIGHT") return addresses.PrivacyBridgeNight;
|
|
1403
1404
|
return addresses.PrivacyBridgeCotiNative;
|
|
1404
1405
|
};
|
|
1405
1406
|
var quoteCotiBridgeFees = async (params) => {
|
|
@@ -1431,7 +1432,7 @@ var quoteCotiBridgeFees = async (params) => {
|
|
|
1431
1432
|
if (isWbtc) {
|
|
1432
1433
|
publicDecimals = 8;
|
|
1433
1434
|
privateDecimals = 8;
|
|
1434
|
-
} else if (isUsdt || isUsdcE || isWada) {
|
|
1435
|
+
} else if (isUsdt || isUsdcE || isWada || isNight) {
|
|
1435
1436
|
publicDecimals = 6;
|
|
1436
1437
|
privateDecimals = 6;
|
|
1437
1438
|
}
|
|
@@ -4168,8 +4169,10 @@ var SYMBOL_TO_ORACLE_BASE = {
|
|
|
4168
4169
|
USDT: "USDT",
|
|
4169
4170
|
USDC: "USDC",
|
|
4170
4171
|
"USDC.e": "USDC",
|
|
4171
|
-
WADA: "ADA"
|
|
4172
|
-
//
|
|
4172
|
+
WADA: "ADA",
|
|
4173
|
+
// Consumer base is uppercase GCOTI (lowercase gCOTI reverts).
|
|
4174
|
+
gCOTI: "GCOTI",
|
|
4175
|
+
NIGHT: "NIGHT"
|
|
4173
4176
|
};
|
|
4174
4177
|
function getPriceConsumerAddress(chainId = 7082400) {
|
|
4175
4178
|
const addresses = CONTRACT_ADDRESSES[chainId];
|
|
@@ -4277,7 +4280,8 @@ var TOKEN_TO_ORACLE_SYMBOL = {
|
|
|
4277
4280
|
USDT: "USDT",
|
|
4278
4281
|
"USDC.e": "USDC",
|
|
4279
4282
|
WADA: "ADA",
|
|
4280
|
-
gCOTI: "GCOTI"
|
|
4283
|
+
gCOTI: "GCOTI",
|
|
4284
|
+
NIGHT: "NIGHT"
|
|
4281
4285
|
};
|
|
4282
4286
|
var TOKEN_DECIMALS = {
|
|
4283
4287
|
COTI: 18,
|
|
@@ -4286,7 +4290,8 @@ var TOKEN_DECIMALS = {
|
|
|
4286
4290
|
USDT: 6,
|
|
4287
4291
|
"USDC.e": 6,
|
|
4288
4292
|
WADA: 6,
|
|
4289
|
-
gCOTI: 18
|
|
4293
|
+
gCOTI: 18,
|
|
4294
|
+
NIGHT: 6
|
|
4290
4295
|
};
|
|
4291
4296
|
async function simulateFeeOnChain(bridgeAddress, amount, fixedFee, percentageBps, maxFee, oracleSymbol, tokenDecimals, provider) {
|
|
4292
4297
|
try {
|
|
@@ -4799,6 +4804,10 @@ var useSnap = (setSnapError) => {
|
|
|
4799
4804
|
}
|
|
4800
4805
|
}, [resolveProvider]);
|
|
4801
4806
|
const isSnapInstalled = useCallback5(async () => {
|
|
4807
|
+
if (!isSnapEnabled()) {
|
|
4808
|
+
logger.log("\u2139\uFE0F Snap disabled via plugin config \u2014 treating as not installed");
|
|
4809
|
+
return false;
|
|
4810
|
+
}
|
|
4802
4811
|
const provider = await resolveProvider();
|
|
4803
4812
|
if (!provider) {
|
|
4804
4813
|
logger.log("\u274C isSnapInstalled: No MetaMask provider");
|
|
@@ -4828,8 +4837,8 @@ var useSnap = (setSnapError) => {
|
|
|
4828
4837
|
}
|
|
4829
4838
|
}, [detectFlask, resolveProvider]);
|
|
4830
4839
|
const connectToSnap = useCallback5(async () => {
|
|
4831
|
-
if (!
|
|
4832
|
-
logger.log("\u2139\uFE0F Snap
|
|
4840
|
+
if (!isSnapEnabled()) {
|
|
4841
|
+
logger.log("\u2139\uFE0F Snap disabled via plugin config");
|
|
4833
4842
|
return false;
|
|
4834
4843
|
}
|
|
4835
4844
|
const provider = await resolveProvider();
|
|
@@ -4976,6 +4985,13 @@ var useSnap = (setSnapError) => {
|
|
|
4976
4985
|
return parseSnapItUint256(result?.value);
|
|
4977
4986
|
}, [connectedAddress, invokeSnapOperation]);
|
|
4978
4987
|
const getAESKeyFromSnap = useCallback5(async (accountAddress, options) => {
|
|
4988
|
+
if (!isSnapEnabled()) {
|
|
4989
|
+
logger.log("\u2139\uFE0F Snap disabled via plugin config \u2014 treating as unavailable");
|
|
4990
|
+
throw new CotiPluginError(
|
|
4991
|
+
"SNAP_CONNECT_FAILED" /* SNAP_CONNECT_FAILED */,
|
|
4992
|
+
"COTI Snap is disabled for this app"
|
|
4993
|
+
);
|
|
4994
|
+
}
|
|
4979
4995
|
if (setSnapError) setSnapError(null);
|
|
4980
4996
|
const skipCache = options?.skipCache === true;
|
|
4981
4997
|
if (isSnapRequestPending.current) {
|
|
@@ -5112,6 +5128,7 @@ var useSnap = (setSnapError) => {
|
|
|
5112
5128
|
}
|
|
5113
5129
|
}, [isSnapInstalled, setSnapError, resolveProvider, syncEnvironment]);
|
|
5114
5130
|
const hasAesKeyInSnap = useCallback5(async (accountAddress) => {
|
|
5131
|
+
if (!isSnapEnabled()) return null;
|
|
5115
5132
|
const provider = await resolveProvider();
|
|
5116
5133
|
if (!provider) return null;
|
|
5117
5134
|
const installed = await isSnapInstalled();
|
|
@@ -5144,6 +5161,10 @@ var useSnap = (setSnapError) => {
|
|
|
5144
5161
|
}
|
|
5145
5162
|
}, [isSnapInstalled, resolveProvider, syncEnvironment]);
|
|
5146
5163
|
const saveAESKeyToSnap = useCallback5(async (key, accountAddress = "") => {
|
|
5164
|
+
if (!isSnapEnabled()) {
|
|
5165
|
+
logger.log("\u2139\uFE0F Snap disabled via plugin config \u2014 skipping AES key save");
|
|
5166
|
+
return false;
|
|
5167
|
+
}
|
|
5147
5168
|
const provider = await resolveProvider();
|
|
5148
5169
|
if (!provider) return false;
|
|
5149
5170
|
try {
|
|
@@ -6582,7 +6603,7 @@ function useWalletType() {
|
|
|
6582
6603
|
const walletType = mapConnectorIdToWalletType(connectorId);
|
|
6583
6604
|
useEffect6(() => {
|
|
6584
6605
|
let cancelled = false;
|
|
6585
|
-
if (walletType !== "metamask" || !connector) {
|
|
6606
|
+
if (walletType !== "metamask" || !connector || !isSnapEnabled()) {
|
|
6586
6607
|
setIsMetaMaskWithSnap(false);
|
|
6587
6608
|
return;
|
|
6588
6609
|
}
|
|
@@ -7671,7 +7692,8 @@ function useAesKeyProvider(walletTypeInfo) {
|
|
|
7671
7692
|
}
|
|
7672
7693
|
}
|
|
7673
7694
|
let savedToSnap = false;
|
|
7674
|
-
const
|
|
7695
|
+
const shouldPersistToSnap = walletTypeInfo.isMetaMaskWithSnap || options.persistToSnap === true;
|
|
7696
|
+
const canSaveToConnectedSnap = !!aesKey && walletTypeInfo.walletType === "metamask" && shouldPersistToSnap && canPersistAesKeyToSnap();
|
|
7675
7697
|
const canSaveEncryptedBackup = aesKey && isValidAesKey(aesKey) && options.saveBackup && servicesEnabled && (services?.saveEncryptedAesBackup || services?.replaceEncryptedAesBackup);
|
|
7676
7698
|
if (canSaveToConnectedSnap) {
|
|
7677
7699
|
emitStep("persisting-key");
|
|
@@ -7683,7 +7705,7 @@ function useAesKeyProvider(walletTypeInfo) {
|
|
|
7683
7705
|
success: "Onboarding succeeded, but the AES key could not be saved to MetaMask Snap. You can retry by unlocking again."
|
|
7684
7706
|
});
|
|
7685
7707
|
}
|
|
7686
|
-
} else if (aesKey && walletTypeInfo.walletType === "metamask" && canPersistAesKeyToSnap() && !
|
|
7708
|
+
} else if (aesKey && walletTypeInfo.walletType === "metamask" && canPersistAesKeyToSnap() && !shouldPersistToSnap) {
|
|
7687
7709
|
logger.log(
|
|
7688
7710
|
"\u2139\uFE0F Skipping Snap AES persist \u2014 Snap is not connected to this origin"
|
|
7689
7711
|
);
|
|
@@ -7768,7 +7790,17 @@ function useAesKeyProvider(walletTypeInfo) {
|
|
|
7768
7790
|
}
|
|
7769
7791
|
}
|
|
7770
7792
|
},
|
|
7771
|
-
[
|
|
7793
|
+
[
|
|
7794
|
+
walletTypeInfo.walletType,
|
|
7795
|
+
walletTypeInfo.isMetaMaskWithSnap,
|
|
7796
|
+
getAESKeyFromSnap,
|
|
7797
|
+
saveAESKeyToSnap,
|
|
7798
|
+
clearSnapCache,
|
|
7799
|
+
connector,
|
|
7800
|
+
connectedChainId,
|
|
7801
|
+
emitStep,
|
|
7802
|
+
reportOnboardingFailure
|
|
7803
|
+
]
|
|
7772
7804
|
);
|
|
7773
7805
|
return {
|
|
7774
7806
|
getAesKey,
|
|
@@ -8151,6 +8183,7 @@ var usePrivacyBridgeNetworkSession = ({
|
|
|
8151
8183
|
};
|
|
8152
8184
|
|
|
8153
8185
|
// src/context/privacyBridge/usePrivacyBridgeAccountSync.ts
|
|
8186
|
+
init_plugin();
|
|
8154
8187
|
import { useCallback as useCallback16, useEffect as useEffect10, useRef as useRef9 } from "react";
|
|
8155
8188
|
import { useAccount as useAccount8 } from "wagmi";
|
|
8156
8189
|
init_logger();
|
|
@@ -8199,13 +8232,13 @@ var usePrivacyBridgeAccountSync = ({
|
|
|
8199
8232
|
);
|
|
8200
8233
|
const getAESKeyForCurrentNetwork = useCallback16(
|
|
8201
8234
|
async (accountAddress, options) => {
|
|
8202
|
-
if (options?.skipCache && walletTypeInfo.walletType === "metamask" && !options.forceContractOnboarding && !options.restoreOnly) {
|
|
8235
|
+
if (options?.skipCache && walletTypeInfo.walletType === "metamask" && isSnapEnabled() && !options.forceContractOnboarding && !options.restoreOnly) {
|
|
8203
8236
|
return getAESKeyFromSnap(accountAddress, { skipCache: true });
|
|
8204
8237
|
}
|
|
8205
8238
|
if (sessionAesKey && !options?.forceContractOnboarding) return sessionAesKey;
|
|
8206
8239
|
return options === void 0 ? getAesKeyFromProvider(accountAddress) : getAesKeyFromProvider(accountAddress, options.onProgress, options);
|
|
8207
8240
|
},
|
|
8208
|
-
[sessionAesKey, getAesKeyFromProvider, getAESKeyFromSnap]
|
|
8241
|
+
[sessionAesKey, getAesKeyFromProvider, getAESKeyFromSnap, walletTypeInfo.walletType]
|
|
8209
8242
|
);
|
|
8210
8243
|
const { updateAccountState } = useBalanceUpdater({
|
|
8211
8244
|
setWalletAddress,
|
|
@@ -11018,8 +11051,8 @@ function usePrivateUnlockController(options = {}) {
|
|
|
11018
11051
|
isPrivateUnlockedRef.current = unlock.isPrivateUnlocked;
|
|
11019
11052
|
const connectedAddress = wallet.walletAddress || "";
|
|
11020
11053
|
const isMetaMaskWallet = walletTypeInfo.walletType === "metamask";
|
|
11021
|
-
const
|
|
11022
|
-
const usesSnapStorage =
|
|
11054
|
+
const canUseSnap = isMetaMaskWallet && !isMetaMaskMobileBrowser() && isSnapEnabled();
|
|
11055
|
+
const usesSnapStorage = canUseSnap && (walletTypeInfo.isMetaMaskWithSnap || snapConnectedInModal);
|
|
11023
11056
|
const isActiveUnlockRequest = useCallback19(
|
|
11024
11057
|
(requestId) => requestId === unlockRequestIdRef.current,
|
|
11025
11058
|
[]
|
|
@@ -11117,7 +11150,7 @@ function usePrivateUnlockController(options = {}) {
|
|
|
11117
11150
|
dismissOnboardModal();
|
|
11118
11151
|
}, [dismissOnboardModal, wallet.walletAddress]);
|
|
11119
11152
|
const connectSnap = useCallback19(async () => {
|
|
11120
|
-
if (!
|
|
11153
|
+
if (!canUseSnap) return false;
|
|
11121
11154
|
setModalError(null);
|
|
11122
11155
|
try {
|
|
11123
11156
|
const connected = await unlock.requestSnapConnection();
|
|
@@ -11136,7 +11169,7 @@ function usePrivateUnlockController(options = {}) {
|
|
|
11136
11169
|
});
|
|
11137
11170
|
return false;
|
|
11138
11171
|
}
|
|
11139
|
-
}, [
|
|
11172
|
+
}, [canUseSnap, unlock]);
|
|
11140
11173
|
const handleRestoreUnlockProgress = useCallback19((step) => {
|
|
11141
11174
|
if (step === "signing-backup") {
|
|
11142
11175
|
setCurrentStep(step);
|
|
@@ -11321,7 +11354,7 @@ function usePrivateUnlockController(options = {}) {
|
|
|
11321
11354
|
contractOnboardingFailureRef.current = null;
|
|
11322
11355
|
try {
|
|
11323
11356
|
let useSnapStorageForOnboarding = usesSnapStorage || snapConnectedInModalRef.current;
|
|
11324
|
-
if (!useSnapStorageForOnboarding &&
|
|
11357
|
+
if (!useSnapStorageForOnboarding && canUseSnap) {
|
|
11325
11358
|
useSnapStorageForOnboarding = await connectSnap();
|
|
11326
11359
|
}
|
|
11327
11360
|
if (!isActiveUnlockRequest(requestId)) {
|
|
@@ -11330,6 +11363,8 @@ function usePrivateUnlockController(options = {}) {
|
|
|
11330
11363
|
const ok = await unlock.refreshPrivateBalances({
|
|
11331
11364
|
forceContractOnboarding: true,
|
|
11332
11365
|
saveBackup: useSnapStorageForOnboarding ? false : saveBackup,
|
|
11366
|
+
// Explicit: don't rely on isMetaMaskWithSnap which can lag after connectSnap.
|
|
11367
|
+
persistToSnap: useSnapStorageForOnboarding,
|
|
11333
11368
|
onProgress: (step, details) => {
|
|
11334
11369
|
if (isActiveUnlockRequest(requestId)) {
|
|
11335
11370
|
handleContractOnboardingProgress(step, details);
|
|
@@ -11385,7 +11420,7 @@ function usePrivateUnlockController(options = {}) {
|
|
|
11385
11420
|
setIsUnlocking(false);
|
|
11386
11421
|
}
|
|
11387
11422
|
}
|
|
11388
|
-
}, [
|
|
11423
|
+
}, [canUseSnap, connectSnap, connectedAddress, currentStep, dismissOnboardModal, handleContractOnboardingProgress, handleOnboardingIncomplete, isActiveUnlockRequest, onOnboardingCancelled, saveBackup, showOnboardingComplete, unlock, usesSnapStorage]);
|
|
11389
11424
|
const handleOnboardModalClose = useCallback19(() => {
|
|
11390
11425
|
if (currentStep === "complete" || currentStep === "validating-key" && pendingCompleteRequestIdRef.current !== null) {
|
|
11391
11426
|
void finishSuccessfulOnboarding();
|
|
@@ -12575,7 +12610,7 @@ export {
|
|
|
12575
12610
|
isChainUpdatesMuted,
|
|
12576
12611
|
isCotiPluginError,
|
|
12577
12612
|
isMultipleWalletsError,
|
|
12578
|
-
|
|
12613
|
+
isSnapEnabled,
|
|
12579
12614
|
loadPodRequests,
|
|
12580
12615
|
logger,
|
|
12581
12616
|
mobileZerionWallet,
|