Skip to content

Commit d46b8ee

Browse files
authored
feat(refactor): Remove ChainSafe Snap (#145)
1 parent 77dc9b8 commit d46b8ee

File tree

10 files changed

+623
-524
lines changed

10 files changed

+623
-524
lines changed

library/extension-assets/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@w3ux/extension-assets-source",
33
"license": "GPL-3.0-only",
4-
"version": "0.4.0",
4+
"version": "1.0.0-beta.1",
55
"type": "module",
66
"scripts": {
77
"clear": "rm -rf node_modules dist tsconfig.tsbuildinfo",

library/extension-assets/src/ChainSafeSnap/icon.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.

library/extension-assets/src/ChainSafeSnap/info.json

Lines changed: 0 additions & 11 deletions
This file was deleted.

library/react-connect-kit/package.json

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
{
22
"name": "@w3ux/react-connect-kit-source",
33
"license": "GPL-3.0-only",
4-
"version": "1.9.0",
4+
"version": "2.0.0-beta.2",
55
"type": "module",
66
"scripts": {
77
"clear": "rm -rf node_modules dist tsconfig.tsbuildinfo",
88
"build": "gulp --silent"
99
},
1010
"dependencies": {
11-
"@chainsafe/metamask-polkadot-adapter": "^0.6.0",
12-
"@polkagate/extension-dapp": "^0.46.13",
13-
"@w3ux/extension-assets": "^0.4.0",
14-
"@w3ux/hooks": "^1.2.1",
15-
"@w3ux/utils": "^1.1.0"
11+
"@polkagate/extension-dapp": "^0.48.2",
12+
"@w3ux/extension-assets": "1.0.0-beta.1",
13+
"@w3ux/hooks": "^1.3.1-beta.7",
14+
"@w3ux/utils": "^1.1.1-beta.11"
1615
},
1716
"devDependencies": {
18-
"@chainsafe/metamask-polkadot-types": "^0.7.0",
1917
"@types/react": "^18",
20-
"@w3ux/types": "^0.2.0",
18+
"@w3ux/types": "^0.2.1-beta.1",
2119
"gulp": "^5.0.0",
2220
"gulp-sourcemaps": "^3.0.0",
2321
"gulp-strip-comments": "^2.6.0",

library/react-connect-kit/src/ExtensionAccountsProvider/index.tsx

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
localStorageOrDefault,
88
setStateWithRef,
99
} from "@w3ux/utils";
10-
import { DEFAULT_SS58, defaultExtensionAccountsContext } from "./defaults";
10+
import { defaultExtensionAccountsContext } from "./defaults";
1111
import { ImportedAccount } from "../types";
1212
import {
1313
ExtensionAccount,
@@ -18,8 +18,6 @@ import {
1818
ExtensionAccountsProviderProps,
1919
} from "./types";
2020
import { useImportExtension } from "./useImportExtension";
21-
import { initPolkadotSnap } from "./snap";
22-
import { SnapNetworks } from "@chainsafe/metamask-polkadot-types";
2321
import { Extensions } from "./Extensions";
2422
import {
2523
connectActiveExtensionAccount,
@@ -104,9 +102,6 @@ export const ExtensionAccountsProvider = ({
104102
return;
105103
}
106104

107-
// Pre-connect: Inject extensions into `injectedWeb3` if not already injected.
108-
await handleExtensionAdapters(extensionIds);
109-
110105
// Iterate previously connected extensions and retreive valid `enable` functions.
111106
// ------------------------------------------------------------------------------
112107
const rawExtensions = Extensions.getFromIds(extensionIds);
@@ -211,9 +206,6 @@ export const ExtensionAccountsProvider = ({
211206
`unknown_extension_${extensionsInitialisedRef.current.length + 1}`
212207
);
213208
} else {
214-
// Pre-connect: Inject into `injectedWeb3` if the provided extension is not already injected.
215-
await handleExtensionAdapters([id]);
216-
217209
try {
218210
// Attempt to get extension `enable` property.
219211
const { enable } = window.injectedWeb3[id];
@@ -306,22 +298,6 @@ export const ExtensionAccountsProvider = ({
306298
updateInitialisedExtensions(id);
307299
};
308300

309-
// Handle adaptors for extensions that are not supported by `injectedWeb3`.
310-
const handleExtensionAdapters = async (extensionIds: string[]) => {
311-
try {
312-
// Connect to Metamask Polkadot Snap and inject into `injectedWeb3` if avaialble.
313-
if (extensionIds.find((id) => id === "metamask-polkadot-snap")) {
314-
await initPolkadotSnap({
315-
networkName: network as SnapNetworks,
316-
addressPrefix: DEFAULT_SS58,
317-
});
318-
}
319-
} catch (e) {
320-
// Provided network is not supported, or something else went wrong with initialisation.
321-
// Silently fail.
322-
}
323-
};
324-
325301
// Update initialised extensions.
326302
const updateInitialisedExtensions = (id: string) => {
327303
if (!extensionsInitialisedRef.current.includes(id)) {

library/react-connect-kit/src/ExtensionAccountsProvider/snap.ts

Lines changed: 0 additions & 98 deletions
This file was deleted.

library/react-connect-kit/src/ExtensionsProvider/index.tsx

Lines changed: 31 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
} from "react";
1313
import type { ExtensionStatus, ExtensionsContextInterface } from "./types";
1414
import { defaultExtensionsContext } from "./defaults";
15-
import { polkadotSnapAvailable } from "./utils";
1615
import extensions from "@w3ux/extension-assets";
1716
import { web3Enable } from "@polkagate/extension-dapp";
1817

@@ -49,11 +48,6 @@ export const ExtensionsProvider = ({
4948
>({});
5049
const extensionsStatusRef = useRef(extensionsStatus);
5150

52-
// Store whether Metamask Snaps are enabled.
53-
const [chainSafeSnapEnabled] = useState<boolean>(
54-
options?.chainSafeSnapEnabled || false
55-
);
56-
5751
// Store whether Metamask Snaps are enabled.
5852
const [polkaGateSnapEnabled] = useState<boolean>(
5953
options?.polkagateSnapEnabled || false
@@ -66,35 +60,46 @@ export const ExtensionsProvider = ({
6660
// Handle completed interval check for `injectedWeb3`.
6761
//
6862
// Clear interval and move on to checking for Metamask Polkadot Snap.
69-
const handleClearInterval = (hasInjectedWeb3: boolean) => {
63+
const handleClearInterval = async (hasInjectedWeb3: boolean) => {
7064
clearInterval(injectedWeb3Interval);
71-
// Check if Metamask Polkadot Snap is available.
72-
handleSnapInjection(hasInjectedWeb3);
73-
};
7465

75-
// Handle injecting of `metamask-polkadot-snap` into injectedWeb3 if avaialble, and complete
76-
// `injectedWeb3` syncing process.
77-
const handleSnapInjection = async (hasInjectedWeb3: boolean) => {
78-
// Inject ChainSafe Snap if enabled.
79-
const snapAvailable =
80-
(await polkadotSnapAvailable()) && chainSafeSnapEnabled;
81-
82-
// Inject PolkaGate Snap if enabled.
66+
// Check if Metamask PolkaGate Snap is available.
8367
if (polkaGateSnapEnabled) {
8468
await withTimeout(500, web3Enable("snap_only"));
85-
}
8669

87-
if (hasInjectedWeb3 || snapAvailable) {
88-
setStateWithRef(
89-
getExtensionsStatus(snapAvailable),
90-
setExtensionsStatus,
91-
extensionsStatusRef
92-
);
70+
if (hasInjectedWeb3) {
71+
setStateWithRef(
72+
getExtensionsStatus(),
73+
setExtensionsStatus,
74+
extensionsStatusRef
75+
);
76+
}
9377
}
94-
9578
setStateWithRef(false, setCheckingInjectedWeb3, checkingInjectedWeb3Ref);
9679
};
9780

81+
// Getter for the currently installed extensions.
82+
//
83+
// Loops through the supported extensios and checks if they are present in `injectedWeb3`. Adds
84+
// `installed` status to the extension if it is present.
85+
const getExtensionsStatus = () => {
86+
const { injectedWeb3 } = window;
87+
const newExtensionsStatus = { ...extensionsStatus };
88+
const extensionsAsArray = Object.entries(extensions).map(
89+
([key, value]) => ({
90+
id: key,
91+
...value,
92+
})
93+
);
94+
extensionsAsArray.forEach((e) => {
95+
if (injectedWeb3[e.id] !== undefined) {
96+
newExtensionsStatus[e.id] = "installed";
97+
}
98+
});
99+
100+
return newExtensionsStatus;
101+
};
102+
98103
// Setter for an extension status.
99104
const setExtensionStatus = (id: string, status: ExtensionStatus) => {
100105
setStateWithRef(
@@ -119,34 +124,6 @@ export const ExtensionsProvider = ({
119124
);
120125
};
121126

122-
// Getter for the currently installed extensions.
123-
//
124-
// Loops through the supported extensios and checks if they are present in `injectedWeb3`. Adds
125-
// `installed` status to the extension if it is present.
126-
const getExtensionsStatus = (snapAvailable: boolean) => {
127-
const { injectedWeb3 } = window;
128-
129-
const newExtensionsStatus = { ...extensionsStatus };
130-
if (snapAvailable) {
131-
newExtensionsStatus["metamask-polkadot-snap"] = "installed";
132-
}
133-
134-
const extensionsAsArray = Object.entries(extensions).map(
135-
([key, value]) => ({
136-
id: key,
137-
...value,
138-
})
139-
);
140-
141-
extensionsAsArray.forEach((e) => {
142-
if (injectedWeb3[e.id] !== undefined) {
143-
newExtensionsStatus[e.id] = "installed";
144-
}
145-
});
146-
147-
return newExtensionsStatus;
148-
};
149-
150127
// Checks if an extension has been installed.
151128
const extensionInstalled = (id: string): boolean =>
152129
extensionsStatus[id] !== undefined;
@@ -179,7 +156,6 @@ export const ExtensionsProvider = ({
179156

180157
injectedWeb3Interval = setInterval(() => {
181158
injectCounter.current++;
182-
183159
if (injectCounter.current === totalChecks) {
184160
handleClearInterval(false);
185161
} else {

0 commit comments

Comments
 (0)