@novastera-oss/nitro-metamask 0.2.6 → 0.2.7
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/android/src/main/java/com/margelo/nitro/nitrometamask/HybridMetamaskConnector.kt +3 -4
- package/android/src/main/java/com/margelo/nitro/nitrometamask/MetamaskContextHolder.kt +36 -0
- package/android/src/main/java/com/margelo/nitro/nitrometamask/NitroMetamaskPackage.kt +4 -1
- package/package.json +1 -1
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
package com.margelo.nitro.nitrometamask
|
|
2
2
|
|
|
3
3
|
import com.margelo.nitro.core.Promise
|
|
4
|
-
import com.margelo.nitro.modules.NitroModulesContextHolder
|
|
5
4
|
import io.metamask.androidsdk.Ethereum
|
|
6
5
|
import io.metamask.androidsdk.Result
|
|
7
6
|
import io.metamask.androidsdk.DappMetadata
|
|
@@ -14,10 +13,10 @@ import kotlin.coroutines.resume
|
|
|
14
13
|
class HybridMetamaskConnector : HybridMetamaskConnectorSpec() {
|
|
15
14
|
// Initialize Ethereum SDK with Context, DappMetadata, and SDKOptions
|
|
16
15
|
// Based on: https://github.com/MetaMask/metamask-android-sdk
|
|
17
|
-
// Using
|
|
16
|
+
// Using MetamaskContextHolder for Context access (Nitro doesn't provide Context APIs)
|
|
17
|
+
// This pattern matches how other Nitro modules handle Context (VisionCamera, MMKV, etc.)
|
|
18
18
|
private val ethereum: Ethereum by lazy {
|
|
19
|
-
val context =
|
|
20
|
-
?: throw IllegalStateException("Application context not available")
|
|
19
|
+
val context = MetamaskContextHolder.get()
|
|
21
20
|
|
|
22
21
|
val dappMetadata = DappMetadata(
|
|
23
22
|
name = "Nitro MetaMask Connector",
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
package com.margelo.nitro.nitrometamask
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Context holder for MetaMask SDK initialization.
|
|
7
|
+
*
|
|
8
|
+
* Nitro does not provide Android Context access, so we must manage it ourselves.
|
|
9
|
+
* This pattern is used by all Nitro modules that need Context (VisionCamera, MMKV, etc.)
|
|
10
|
+
*
|
|
11
|
+
* The context is initialized from NitroMetamaskPackage when React Native loads the module.
|
|
12
|
+
*/
|
|
13
|
+
object MetamaskContextHolder {
|
|
14
|
+
@Volatile
|
|
15
|
+
private var appContext: Context? = null
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Initialize the context holder with the React Native application context.
|
|
19
|
+
* This should be called once from NitroMetamaskPackage.getModule()
|
|
20
|
+
*/
|
|
21
|
+
fun initialize(context: Context) {
|
|
22
|
+
appContext = context.applicationContext
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Get the application context.
|
|
27
|
+
* Throws if not initialized - this ensures we fail fast if the package wasn't loaded correctly.
|
|
28
|
+
*/
|
|
29
|
+
fun get(): Context {
|
|
30
|
+
return appContext
|
|
31
|
+
?: throw IllegalStateException(
|
|
32
|
+
"MetamaskContextHolder not initialized. " +
|
|
33
|
+
"Make sure NitroMetamaskPackage is properly registered in your React Native app."
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -7,7 +7,10 @@ import com.facebook.react.BaseReactPackage
|
|
|
7
7
|
|
|
8
8
|
class NitroMetamaskPackage : BaseReactPackage() {
|
|
9
9
|
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
|
|
10
|
-
//
|
|
10
|
+
// Initialize MetamaskContextHolder with React Native application context
|
|
11
|
+
// This is the ONLY way to get Context in Nitro modules - Nitro doesn't provide Context APIs
|
|
12
|
+
// The context is stored in our own holder and accessed by HybridMetamaskConnector
|
|
13
|
+
MetamaskContextHolder.initialize(reactContext)
|
|
11
14
|
return null
|
|
12
15
|
}
|
|
13
16
|
|