@multiplatform.one/web3 7.90.0 → 7.90.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@multiplatform.one/web3",
3
- "version": "7.90.0",
3
+ "version": "7.90.2",
4
4
  "description": "Web3 wallet integration for multiplatform.one ecosystem with ConnectKit and wagmi",
5
5
  "keywords": [
6
6
  "connectkit",
@@ -120,10 +120,10 @@
120
120
  "@aave/account": "^0.2.1",
121
121
  "@coinbase/wallet-sdk": "^4.4.0",
122
122
  "@metamask/connect-evm": "^2.1.1",
123
- "@multiplatform.one/connectkit": "^7.90.0",
124
- "@multiplatform.one/gpg": "^7.90.0",
125
- "@multiplatform.one/platform": "^7.90.0",
126
- "@multiplatform.one/theme": "^7.90.0",
123
+ "@multiplatform.one/connectkit": "^7.90.2",
124
+ "@multiplatform.one/gpg": "^7.90.2",
125
+ "@multiplatform.one/platform": "^7.90.2",
126
+ "@multiplatform.one/theme": "^7.90.2",
127
127
  "@noble/ciphers": "^1.3.0",
128
128
  "@noble/curves": "^1.9.7",
129
129
  "@phosphor-icons/react": "^2.1.10",
@@ -147,8 +147,8 @@
147
147
  "wagmi": "^3.7.1"
148
148
  },
149
149
  "devDependencies": {
150
- "@multiplatform.one/config": "7.90.0",
151
- "@multiplatform.one/test-utils": "7.90.0",
150
+ "@multiplatform.one/config": "7.90.2",
151
+ "@multiplatform.one/test-utils": "7.90.2",
152
152
  "@tamagui/build": "2.7.6",
153
153
  "@tanstack/react-query": "^5.104.3",
154
154
  "@testing-library/jest-dom": "^7.0.1",
@@ -0,0 +1,104 @@
1
+ // @vitest-environment happy-dom
2
+ import React, { useState } from "react";
3
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
4
+ import { act, cleanup, render } from "@testing-library/react";
5
+ import { ConnectKitThemeProvider, Context } from "@multiplatform.one/connectkit";
6
+
7
+ import ConnectWithInjector from ".";
8
+
9
+ type Mutation = {
10
+ onSettled?: (data?: unknown, error?: unknown) => void;
11
+ };
12
+
13
+ const captured: { mutation?: Mutation } = {};
14
+
15
+ vi.mock("../../../hooks/useConnect", () => ({
16
+ useConnect: ({ mutation }: { mutation: Mutation }) => {
17
+ captured.mutation = mutation;
18
+ return { connect: vi.fn() };
19
+ },
20
+ }));
21
+
22
+ vi.mock("../../../wallets/useWallets", () => ({
23
+ useWallet: () => ({
24
+ id: "mock",
25
+ name: "Mock Wallet",
26
+ connector: { id: "mock", uid: "mock-uid" },
27
+ isInstalled: false,
28
+ }),
29
+ }));
30
+
31
+ function Harness({ onResize }: { onResize: () => void }) {
32
+ const [, setResize] = useState(0);
33
+ const value = {
34
+ connector: { id: "mock" },
35
+ options: {},
36
+ log: () => {},
37
+ triggerResize: () => {
38
+ onResize();
39
+ setResize((prev) => prev + 1);
40
+ },
41
+ } as unknown as React.ContextType<typeof Context>;
42
+ return (
43
+ <Context.Provider value={value}>
44
+ <ConnectKitThemeProvider>
45
+ <ConnectWithInjector />
46
+ </ConnectKitThemeProvider>
47
+ </Context.Provider>
48
+ );
49
+ }
50
+
51
+ describe("ConnectWithInjector", () => {
52
+ beforeEach(() => {
53
+ vi.useFakeTimers();
54
+ });
55
+
56
+ afterEach(() => {
57
+ cleanup();
58
+ vi.unstubAllGlobals();
59
+ vi.useRealTimers();
60
+ captured.mutation = undefined;
61
+ });
62
+
63
+ it("drops its pending timers when it unmounts", () => {
64
+ const onResize = vi.fn();
65
+ const consoleError = vi.spyOn(console, "error").mockImplementation(() => {});
66
+ const { unmount } = render(<Harness onResize={onResize} />);
67
+
68
+ act(() => {
69
+ captured.mutation?.onSettled?.(undefined, { code: 4001 });
70
+ });
71
+ unmount();
72
+ vi.stubGlobal("window", undefined);
73
+
74
+ expect(() => vi.advanceTimersByTime(5000)).not.toThrow();
75
+ expect(onResize).not.toHaveBeenCalled();
76
+ expect(consoleError).not.toHaveBeenCalled();
77
+ });
78
+
79
+ it("schedules nothing when the connect settles after unmount", () => {
80
+ const onResize = vi.fn();
81
+ const { unmount } = render(<Harness onResize={onResize} />);
82
+
83
+ unmount();
84
+ captured.mutation?.onSettled?.(undefined, { code: 4001 });
85
+ vi.stubGlobal("window", undefined);
86
+
87
+ expect(() => vi.advanceTimersByTime(5000)).not.toThrow();
88
+ expect(onResize).not.toHaveBeenCalled();
89
+ });
90
+
91
+ it("still resizes while mounted", () => {
92
+ const onResize = vi.fn();
93
+ render(<Harness onResize={onResize} />);
94
+
95
+ act(() => {
96
+ captured.mutation?.onSettled?.(undefined, { code: 4001 });
97
+ });
98
+ act(() => {
99
+ vi.advanceTimersByTime(100);
100
+ });
101
+
102
+ expect(onResize).toHaveBeenCalledTimes(1);
103
+ });
104
+ });
@@ -1,5 +1,5 @@
1
1
  import { motionSeconds } from "@multiplatform.one/theme/motion";
2
- import React, { useEffect, useState } from "react";
2
+ import React, { useEffect, useRef, useState } from "react";
3
3
  import { AnimatePresence, Variants } from "framer-motion";
4
4
  import {
5
5
  Container,
@@ -83,6 +83,18 @@ const contentVariants: Variants = {
83
83
  const ConnectWithInjector: React.FC<{
84
84
  forceState?: typeof states;
85
85
  }> = ({ forceState }) => {
86
+ const timers = useRef<ReturnType<typeof setTimeout>[] | null>([]);
87
+ useEffect(() => {
88
+ timers.current = [];
89
+ return () => {
90
+ timers.current?.forEach(clearTimeout);
91
+ timers.current = null;
92
+ };
93
+ }, []);
94
+ const schedule = (fn: () => void, ms: number) => {
95
+ timers.current?.push(setTimeout(fn, ms));
96
+ };
97
+
86
98
  const { connect } = useConnect({
87
99
  mutation: {
88
100
  onMutate: (connector?: any) => {
@@ -98,7 +110,7 @@ const ConnectWithInjector: React.FC<{
98
110
  onSettled(data?: any, error?: any) {
99
111
  if (error) {
100
112
  setShowTryAgainTooltip(true);
101
- setTimeout(() => setShowTryAgainTooltip(false), 3500);
113
+ schedule(() => setShowTryAgainTooltip(false), 3500);
102
114
  if (error.code) {
103
115
  // https://github.com/MetaMask/eth-rpc-errors/blob/main/src/error-constants.ts
104
116
  switch (error.code) {
@@ -127,7 +139,7 @@ const ConnectWithInjector: React.FC<{
127
139
  }
128
140
  } else if (data) {
129
141
  }
130
- setTimeout(triggerResize, 100);
142
+ schedule(triggerResize, 100);
131
143
  },
132
144
  },
133
145
  });
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/connectkit/components/ConnectModal/ConnectWithInjector/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAA8B,MAAM,OAAO,CAAC;AA0CnD,eAAO,MAAM,MAAM;;;;;;;;CAQlB,CAAC;AA+BF,QAAA,MAAM,mBAAmB,EAAE,KAAK,CAAC,EAAE,CAAC;IAClC,UAAU,CAAC,EAAE,OAAO,MAAM,CAAC;CAC5B,CAwbA,CAAC;AAEF,eAAe,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/connectkit/components/ConnectModal/ConnectWithInjector/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAsC,MAAM,OAAO,CAAC;AA0C3D,eAAO,MAAM,MAAM;;;;;;;;CAQlB,CAAC;AA+BF,QAAA,MAAM,mBAAmB,EAAE,KAAK,CAAC,EAAE,CAAC;IAClC,UAAU,CAAC,EAAE,OAAO,MAAM,CAAC;CAC5B,CAocA,CAAC;AAEF,eAAe,mBAAmB,CAAC"}