Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove react-native-mmkv dependency #208

Open
wants to merge 2 commits into
base: 2.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package expo.modules.coinbasewalletsdkexpo

import android.content.Context
import android.net.Uri
import android.util.Log
import com.coinbase.android.nativesdk.CoinbaseWalletSDK
Expand All @@ -22,6 +23,9 @@ import expo.modules.kotlin.records.Record

class CoinbaseWalletSDKModule : Module() {
private var sdk: CoinbaseWalletSDK? = null
private val sharedPref by lazy {
appContext.reactContext?.applicationContext?.getSharedPreferences("mwp_kv_storage", Context.MODE_PRIVATE)
}

override fun definition() = ModuleDefinition {

Expand Down Expand Up @@ -122,5 +126,23 @@ class CoinbaseWalletSDKModule : Module() {
Function("resetSession") {
sdk?.resetSession()
}

Function("setValue") { key: String, value: String ->
val store = sharedPref ?: return@Function
store.edit()
.putString(key, value)
.apply()
}

Function("getValue") { key: String ->
return@Function sharedPref?.getString(key, null)
}

Function("deleteValue") { key: String ->
val store = sharedPref ?: return@Function
store.edit()
.remove(key)
.apply()
}
}
}
9 changes: 2 additions & 7 deletions react-native/client/example/App.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import {useState, useMemo, useEffect, useCallback} from 'react';
import {useState, useEffect, useCallback} from 'react';
import {
Button,
Linking,
Expand All @@ -18,7 +18,6 @@ import {
handleResponse,
WalletMobileSDKEVMProvider,
} from '@coinbase/wallet-mobile-sdk';
import {MMKV} from 'react-native-mmkv';

// Configure Mobile SDK
configure({
Expand All @@ -28,13 +27,11 @@ configure({
});

const provider = new WalletMobileSDKEVMProvider();
const storage = new MMKV();

const App = function () {
const [log, setLog] = useState('');

const cachedAddress = useMemo(() => storage.getString('address'), []);
const [address, setAddress] = useState(cachedAddress);
const [address, setAddress] = useState(provider.selectedAddress);

const isConnected = address !== undefined;

Expand Down Expand Up @@ -64,7 +61,6 @@ const App = function () {
params: [],
});
setAddress(accounts[0]);
storage.set('address', accounts[0]);

logMessage(`<-- ${accounts}`);
} catch (e) {
Expand All @@ -79,7 +75,6 @@ const App = function () {

provider.disconnect();
setAddress(undefined);
storage.delete('address');
}, [logMessage]);

const personalSign = useCallback(async () => {
Expand Down
4 changes: 2 additions & 2 deletions react-native/client/example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ android {

compileSdkVersion rootProject.ext.compileSdkVersion

namespace 'com.anonymous.example'
namespace 'com.example.rndapp'
defaultConfig {
applicationId 'com.anonymous.example'
applicationId 'com.example.rndapp'
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* <p>This source code is licensed under the MIT license found in the LICENSE file in the root
* directory of this source tree.
*/
package com.anonymous.example;
package com.example.rndapp;

import android.content.Context;
import com.facebook.flipper.android.AndroidFlipperClient;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.anonymous.example">
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.rndapp">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
Expand All @@ -16,7 +16,7 @@
<meta-data android:name="expo.modules.updates.EXPO_SDK_VERSION" android:value="48.0.0"/>
<meta-data android:name="expo.modules.updates.EXPO_UPDATES_CHECK_ON_LAUNCH" android:value="ALWAYS"/>
<meta-data android:name="expo.modules.updates.EXPO_UPDATES_LAUNCH_WAIT_MS" android:value="0"/>
<meta-data android:name="expo.modules.updates.EXPO_UPDATE_URL" android:value="https://exp.host/@anonymous/example"/>
<meta-data android:name="expo.modules.updates.EXPO_UPDATE_URL" android:value="https://exp.host/@anonymous/example-rn-dapp"/>
<activity android:name=".MainActivity" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize" android:theme="@style/Theme.App.SplashScreen" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
Expand All @@ -26,7 +26,8 @@
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="com.anonymous.example"/>
<data android:scheme="example.rn.dapp"/>
<data android:scheme="com.example.rndapp"/>
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" android:exported="false"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.anonymous.example;
package com.example.rndapp;

import android.os.Build;
import android.os.Bundle;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.anonymous.example;
package com.example.rndapp;

import android.app.Application;
import android.content.res.Configuration;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<resources>
<string name="app_name">example</string>
<string name="app_name">Example RN Dapp</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* <p>This source code is licensed under the MIT license found in the LICENSE file in the root
* directory of this source tree.
*/
package com.anonymous.example;
package com.example.rndapp;

import android.content.Context;
import com.facebook.react.ReactInstanceManager;
Expand Down
2 changes: 1 addition & 1 deletion react-native/client/example/android/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
rootProject.name = 'example'
rootProject.name = 'Example RN Dapp'

apply from: new File(["node", "--print", "require.resolve('expo/package.json')"].execute(null, rootDir).text.trim(), "../scripts/autolinking.gradle");
useExpoModules()
Expand Down
35 changes: 19 additions & 16 deletions react-native/client/example/app.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
{
"name": "example",
"displayName": "example",
"android": {
"package": "com.anonymous.example"
},
"ios": {
"bundleIdentifier": "com.anonymous.example"
},
"plugins": [
[
"expo-build-properties",
{
"android": {
"minSdkVersion": 23
"expo": {
"name": "Example RN Dapp",
"slug": "example-rn-dapp",
"scheme": "example.rn.dapp",
"android": {
"package": "com.example.rndapp"
},
"ios": {
"bundleIdentifier": "com.example.rndapp"
},
"plugins": [
[
"expo-build-properties",
{
"android": {
"minSdkVersion": 23
}
}
}
]
]
]
}
}
Loading