NFC access for Dapps (#670)
This commit is contained in:
parent
30fb48523e
commit
0944df715f
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "StatusIm",
|
"name": "StatusIm",
|
||||||
"interface": "reagent",
|
"interface": "reagent",
|
||||||
"androidHost": "localhost",
|
"androidHost": "10.0.3.2",
|
||||||
"modules": [
|
"modules": [
|
||||||
"react-native-contacts",
|
"react-native-contacts",
|
||||||
"react-native-invertible-scroll-view",
|
"react-native-invertible-scroll-view",
|
||||||
|
@ -37,7 +37,8 @@
|
||||||
"react-native-share",
|
"react-native-share",
|
||||||
"react-native-emoji-picker",
|
"react-native-emoji-picker",
|
||||||
"react-native-autolink",
|
"react-native-autolink",
|
||||||
"instabug-reactnative"
|
"instabug-reactnative",
|
||||||
|
"nfc-react-native"
|
||||||
],
|
],
|
||||||
"imageDirs": [
|
"imageDirs": [
|
||||||
"images"
|
"images"
|
||||||
|
|
|
@ -158,6 +158,7 @@ android {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
compile project(':nfc-react-native')
|
||||||
compile project(':instabug-reactnative')
|
compile project(':instabug-reactnative')
|
||||||
compile project(':react-native-splash-screen')
|
compile project(':react-native-splash-screen')
|
||||||
compile project(':react-native-image-resizer')
|
compile project(':react-native-image-resizer')
|
||||||
|
|
|
@ -3,6 +3,7 @@ package im.status.ethereum;
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
|
|
||||||
import com.facebook.react.ReactApplication;
|
import com.facebook.react.ReactApplication;
|
||||||
|
import es.tiarg.nfcreactnative.NfcReactNativePackage;
|
||||||
import com.instabug.reactlibrary.RNInstabugReactnativePackage;
|
import com.instabug.reactlibrary.RNInstabugReactnativePackage;
|
||||||
import com.cboy.rn.splashscreen.SplashScreenReactPackage;
|
import com.cboy.rn.splashscreen.SplashScreenReactPackage;
|
||||||
import com.facebook.react.ReactNativeHost;
|
import com.facebook.react.ReactNativeHost;
|
||||||
|
@ -41,6 +42,7 @@ public class MainApplication extends Application implements ReactApplication {
|
||||||
protected List<ReactPackage> getPackages() {
|
protected List<ReactPackage> getPackages() {
|
||||||
return Arrays.asList(
|
return Arrays.asList(
|
||||||
new MainReactPackage(),
|
new MainReactPackage(),
|
||||||
|
new NfcReactNativePackage(),
|
||||||
new RNInstabugReactnativePackage("b239f82a9cb00464e4c72cc703e6821e",MainApplication.this,"shake"),
|
new RNInstabugReactnativePackage("b239f82a9cb00464e4c72cc703e6821e",MainApplication.this,"shake"),
|
||||||
new SplashScreenReactPackage(),
|
new SplashScreenReactPackage(),
|
||||||
new StatusPackage(),
|
new StatusPackage(),
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
rootProject.name = 'StatusIm'
|
rootProject.name = 'StatusIm'
|
||||||
|
|
||||||
include ':app'
|
include ':app'
|
||||||
|
include ':nfc-react-native'
|
||||||
|
project(':nfc-react-native').projectDir = new File(rootProject.projectDir, '../node_modules/nfc-react-native/android')
|
||||||
include ':instabug-reactnative'
|
include ':instabug-reactnative'
|
||||||
project(':instabug-reactnative').projectDir = new File(rootProject.projectDir, '../node_modules/instabug-reactnative/android')
|
project(':instabug-reactnative').projectDir = new File(rootProject.projectDir, '../node_modules/instabug-reactnative/android')
|
||||||
include ':react-native-splash-screen'
|
include ':react-native-splash-screen'
|
||||||
|
|
|
@ -198,5 +198,8 @@ var TopLevel = {
|
||||||
"_value" : function () {},
|
"_value" : function () {},
|
||||||
"ListView": function() {},
|
"ListView": function() {},
|
||||||
"DataSource": function() {},
|
"DataSource": function() {},
|
||||||
"IBGLog": function() {}
|
"IBGLog": function() {},
|
||||||
|
"getCardId": function() {},
|
||||||
|
"readTag": function() {},
|
||||||
|
"writeTag": function() {}
|
||||||
};
|
};
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
"https-browserify": "0.0.1",
|
"https-browserify": "0.0.1",
|
||||||
"identicon.js": "github:status-im/identicon.js",
|
"identicon.js": "github:status-im/identicon.js",
|
||||||
"instabug-reactnative": "git+https://github.com/status-im/instabug-reactnative.git",
|
"instabug-reactnative": "git+https://github.com/status-im/instabug-reactnative.git",
|
||||||
|
"nfc-react-native": "^0.3.9",
|
||||||
"os-browserify": "^0.1.2",
|
"os-browserify": "^0.1.2",
|
||||||
"path-browserify": "0.0.0",
|
"path-browserify": "0.0.0",
|
||||||
"process": "^0.11.5",
|
"process": "^0.11.5",
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
[status-im.models.commands :as commands]
|
[status-im.models.commands :as commands]
|
||||||
[status-im.commands.utils :as cu]
|
[status-im.commands.utils :as cu]
|
||||||
[status-im.components.status :as s]
|
[status-im.components.status :as s]
|
||||||
|
[status-im.components.nfc :as nfc]
|
||||||
[status-im.constants :as c]
|
[status-im.constants :as c]
|
||||||
[cljs.reader :refer [read-string]]
|
[cljs.reader :refer [read-string]]
|
||||||
[status-im.navigation.handlers :as nav]))
|
[status-im.navigation.handlers :as nav]))
|
||||||
|
@ -92,6 +93,7 @@
|
||||||
:params params}])
|
:params params}])
|
||||||
:webview-scan-qr (dispatch [:show-scan-qr :webview-address-from-qr])
|
:webview-scan-qr (dispatch [:show-scan-qr :webview-address-from-qr])
|
||||||
:webview-send-eth (dispatch [:webview-send-eth! params])
|
:webview-send-eth (dispatch [:webview-send-eth! params])
|
||||||
|
:nfc (dispatch [:webview-nfc params])
|
||||||
(log/error (str "Unknown event: " event')))))))
|
(log/error (str "Unknown event: " event')))))))
|
||||||
|
|
||||||
(defmethod nav/preload-data! :contact-list-modal
|
(defmethod nav/preload-data! :contact-list-modal
|
||||||
|
@ -127,3 +129,21 @@
|
||||||
parameters
|
parameters
|
||||||
(fn [data]
|
(fn [data]
|
||||||
(log/debug :webview-send-eth-callback data)))))))
|
(log/debug :webview-send-eth-callback data)))))))
|
||||||
|
|
||||||
|
(register-handler :webview-nfc
|
||||||
|
(u/side-effect!
|
||||||
|
(fn [_ [_ {:keys [event params]}]]
|
||||||
|
(let [callback #(dispatch [:send-to-webview-bridge {:params % :event "nfc"}])]
|
||||||
|
(case (keyword event)
|
||||||
|
:get-card-id (nfc/get-card-id #(callback {:event :get-card-id :card %})
|
||||||
|
#(callback {:event :get-card-id :error %}))
|
||||||
|
:read-tag (let [{:keys [sectors]} params]
|
||||||
|
(nfc/read-tag sectors
|
||||||
|
#(callback {:event :read-tag :card %})
|
||||||
|
#(callback {:event :read-tag :error %})))
|
||||||
|
:write-tag (let [{:keys [sectors id]} params]
|
||||||
|
(nfc/write-tag sectors
|
||||||
|
id
|
||||||
|
#(callback {:event :write-tag :card %})
|
||||||
|
#(callback {:event :write-tag :error %})))
|
||||||
|
:default)))))
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
[status-im.i18n :refer [label]]
|
[status-im.i18n :refer [label]]
|
||||||
[status-im.components.react :refer [dismiss-keyboard!]]
|
[status-im.components.react :refer [dismiss-keyboard!]]
|
||||||
[clojure.string :as str]
|
[clojure.string :as str]
|
||||||
[cljs.spec :as s]
|
|
||||||
[status-im.components.chat-icon.screen :as ci]))
|
[status-im.components.chat-icon.screen :as ci]))
|
||||||
|
|
||||||
(defonce drawer-atom (atom))
|
(defonce drawer-atom (atom))
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
(ns status-im.components.nfc
|
||||||
|
(:require [cljs.spec :as s]
|
||||||
|
[status-im.utils.platform :as platform]))
|
||||||
|
|
||||||
|
(def class
|
||||||
|
(when platform/android?
|
||||||
|
(js/require "nfc-react-native")))
|
||||||
|
|
||||||
|
(def android-only-error "NFC API is available only on Android")
|
||||||
|
|
||||||
|
(defn get-card-id [on-success on-error]
|
||||||
|
(if platform/android?
|
||||||
|
(-> (.getCardId class)
|
||||||
|
(.then on-success)
|
||||||
|
(.catch on-error))
|
||||||
|
(on-error android-only-error)))
|
||||||
|
|
||||||
|
(defn read-tag [sectors on-success on-error]
|
||||||
|
(if platform/android?
|
||||||
|
(-> (.readTag class (clj->js sectors))
|
||||||
|
(.then on-success)
|
||||||
|
(.catch on-error))
|
||||||
|
(on-error android-only-error)))
|
||||||
|
|
||||||
|
(defn write-tag [sectors card-id on-success on-error]
|
||||||
|
(if platform/android?
|
||||||
|
(-> (.writeTag class (clj->js sectors) card-id)
|
||||||
|
(.then on-success)
|
||||||
|
(.catch on-error))
|
||||||
|
(on-error android-only-error)))
|
Loading…
Reference in New Issue