@@ -12,7 +12,6 @@ import {
1212} from "react" ;
1313import type { ExtensionStatus , ExtensionsContextInterface } from "./types" ;
1414import { defaultExtensionsContext } from "./defaults" ;
15- import { polkadotSnapAvailable } from "./utils" ;
1615import extensions from "@w3ux/extension-assets" ;
1716import { 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