@coti-io/coti-wallet-plugin 0.2.0 → 0.2.1

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.js CHANGED
@@ -3828,6 +3828,17 @@ var usePrivateTokenBalance = () => {
3828
3828
  if (error instanceof CotiPluginError) {
3829
3829
  throw error;
3830
3830
  }
3831
+ const message = error instanceof Error ? error.message : String(error?.message ?? error ?? "");
3832
+ const code = error?.code;
3833
+ const isDecryptPayloadFailure = message.includes("Invalid encrypted payload") || code === -32603 && /encrypt|decrypt|ciphertext/i.test(message);
3834
+ if (isDecryptPayloadFailure || canUseSnapDecrypt) {
3835
+ logger.error(`\u274C Failed to decrypt private balance for ${contractAddress}`, error);
3836
+ throw new CotiPluginError(
3837
+ "AES_KEY_MISMATCH" /* AES_KEY_MISMATCH */,
3838
+ isDecryptPayloadFailure ? "Could not decrypt private balances. The Snap AES key may be missing or invalid \u2014 re-onboarding is required." : "Could not decrypt private balances via Snap. Re-onboarding may be required.",
3839
+ message
3840
+ );
3841
+ }
3831
3842
  logger.error(`\u274C Failed to fetch/decrypt for ${contractAddress}`, error);
3832
3843
  return "0.00";
3833
3844
  }
@@ -4228,7 +4239,7 @@ var useBalanceUpdater = ({
4228
4239
  return { symbol: token.symbol, value, isMismatch: false };
4229
4240
  } catch (e) {
4230
4241
  const msg = e?.message || "";
4231
- const isMismatch = msg.includes("AES key mismatch") || msg.includes("onboarding") || msg.includes("ACCOUNT_NOT_ONBOARDED") || msg.includes("implausible decrypted balance");
4242
+ const isMismatch = e instanceof CotiPluginError && (e.code === "AES_KEY_MISMATCH" /* AES_KEY_MISMATCH */ || e.code === "ACCOUNT_NOT_ONBOARDED" /* ACCOUNT_NOT_ONBOARDED */) || msg.includes("AES key mismatch") || msg.includes("Invalid encrypted payload") || msg.includes("onboarding") || msg.includes("ACCOUNT_NOT_ONBOARDED") || msg.includes("implausible decrypted balance");
4232
4243
  if (isMismatch) {
4233
4244
  logger.warn(`\u26A0\uFE0F Private token decrypt mismatch for ${tokenAddress}. Falling back to 0.`);
4234
4245
  return { symbol: token.symbol, value: "0", isMismatch: true };