Skip to content

Commit

Permalink
fix: android support old arch
Browse files Browse the repository at this point in the history
  • Loading branch information
amper-fb committed Apr 24, 2024
1 parent 5fa6b0a commit 0bd3b0a
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 31 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Fireblocks NCW SDK bridge for React Native
npm install @fireblocks/react-native-ncw-sdk
```

### Android additional setup

Add the Maven repository and SDK dependency to your app as described [here](https://ncw-developers.fireblocks.com/docs/setup-4#android-sdk-installation)

### iOS additional setup
1. Edit the following line to your app's `Podfile`

Expand All @@ -19,11 +23,13 @@ npm install @fireblocks/react-native-ncw-sdk
2. Install pod dependencies:

```sh
cd example/ios && bundle exec pod install
cd ios && bundle exec pod install
```
3. Open your project's workspace in xcode
3. Open your project's workspace in Xcode

4. Add Fireblocks SDK Swift Package as described [here](https://ncw-developers.fireblocks.com/docs/setup-4#ios-sdk-installation), or:

4. File > Add Package Dependecies... > https://github.com/fireblocks/ncw-ios-sdk > Add Package > Add to Target: "Your Project" > Add Package
File > Add Package Dependecies... > https://github.com/fireblocks/ncw-ios-sdk > Add Package > Add to Target: "Your Project" > Add Package

## Usage

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class ReactNativeNcwSdkModule internal constructor(context: ReactApplicationCont
listenerCount -= count
}

@ReactMethod
override fun handleResponse(response: ReadableMap, promise: Promise) {
val opId = response.getInt("opId")
val cb = operations.remove(opId)
Expand All @@ -129,10 +130,12 @@ class ReactNativeNcwSdkModule internal constructor(context: ReactApplicationCont
}
}

@ReactMethod
override fun getPhysicalDeviceId(): String {
return Fireblocks.getPhysicalDeviceId()
}

@ReactMethod
override fun initialize(deviceId: String, promise: Promise) {
if (ReactNativeNcwSdkModule.initializedDevices.contains(deviceId)) {
Log.d(TAG, "Device already initialized: $deviceId")
Expand Down Expand Up @@ -400,6 +403,7 @@ class ReactNativeNcwSdkModule internal constructor(context: ReactApplicationCont
}
}

@ReactMethod
override fun getKeysStatus(deviceId: String, promise: Promise) {
try {
val instance: Fireblocks = Fireblocks.getInstance(deviceId)
Expand All @@ -419,6 +423,7 @@ class ReactNativeNcwSdkModule internal constructor(context: ReactApplicationCont
}
}

@ReactMethod
override fun generateMPCKeys(deviceId: String, algorithms: ReadableArray, promise: Promise) {
try {
val instance: Fireblocks = Fireblocks.getInstance(deviceId)
Expand All @@ -443,6 +448,7 @@ class ReactNativeNcwSdkModule internal constructor(context: ReactApplicationCont
}
}

@ReactMethod
override fun backupKeys(
deviceId: String,
passphrase: String,
Expand All @@ -467,6 +473,7 @@ class ReactNativeNcwSdkModule internal constructor(context: ReactApplicationCont
}
}

@ReactMethod
override fun recoverKeys(deviceId: String, promise: Promise) {
try {
val instance: Fireblocks = Fireblocks.getInstance(deviceId)
Expand Down Expand Up @@ -511,6 +518,7 @@ class ReactNativeNcwSdkModule internal constructor(context: ReactApplicationCont
}
}

@ReactMethod
override fun takeover(deviceId: String, promise: Promise) {
try {
Log.d(TAG, "Takeover deviceId: $deviceId")
Expand All @@ -534,6 +542,7 @@ class ReactNativeNcwSdkModule internal constructor(context: ReactApplicationCont
}
}

@ReactMethod
override fun requestJoinExistingWallet(deviceId: String, promise: Promise) {
try {
val handler = JoinWalletHandler(
Expand Down Expand Up @@ -568,6 +577,7 @@ class ReactNativeNcwSdkModule internal constructor(context: ReactApplicationCont
}
}

@ReactMethod
override fun stopJoinWallet(deviceId: String) {
try {
Log.d(TAG, "Stop Join Wallet deviceId: $deviceId")
Expand All @@ -578,6 +588,7 @@ class ReactNativeNcwSdkModule internal constructor(context: ReactApplicationCont
}
}

@ReactMethod
override fun approveJoinWalletRequest(deviceId: String, requestId: String, promise: Promise) {
try {
Log.d(TAG, "Approve Join Wallet Request deviceId: $deviceId")
Expand Down Expand Up @@ -637,6 +648,7 @@ class ReactNativeNcwSdkModule internal constructor(context: ReactApplicationCont
// }
// }

@ReactMethod
override fun deriveAssetKey(
deviceId: String,
extendedPrivateKey: String,
Expand All @@ -660,34 +672,36 @@ class ReactNativeNcwSdkModule internal constructor(context: ReactApplicationCont
}
}

override fun signTransaction(deviceId: String, txId: String, promise: Promise) {
try {
val instance: Fireblocks = Fireblocks.getInstance(deviceId)
instance.signTransaction(txId) { signedTx: TransactionSignature ->
promise.resolve(signedTx.transactionSignatureStatus.toString())
}
} catch (e: Exception) {
promise.reject("Error", e.message)
return
}
}
@ReactMethod
override fun signTransaction(deviceId: String, txId: String, promise: Promise) {
try {
val instance: Fireblocks = Fireblocks.getInstance(deviceId)
instance.signTransaction(txId) { signedTx: TransactionSignature ->
promise.resolve(signedTx.transactionSignatureStatus.toString())
}
} catch (e: Exception) {
promise.reject("Error", e.message)
return
}
}

override fun getTransactionSignatureStatus(deviceId: String, txId: String, promise: Promise) {
try {
val instance: Fireblocks = Fireblocks.getInstance(deviceId)
val signedTx: TransactionSignature? = instance.getTransactionSignatureStatus(txId)
promise.resolve(signedTx?.transactionSignatureStatus.toString())
} catch (e: Exception) {
promise.reject("Error", e.message)
return
}
}
@ReactMethod
override fun getTransactionSignatureStatus(deviceId: String, txId: String, promise: Promise) {
try {
val instance: Fireblocks = Fireblocks.getInstance(deviceId)
val signedTx: TransactionSignature? = instance.getTransactionSignatureStatus(txId)
promise.resolve(signedTx?.transactionSignatureStatus.toString())
} catch (e: Exception) {
promise.reject("Error", e.message)
return
}
}

companion object {
private const val TAG = "Fireblocks:NCW"
companion object {
private const val TAG = "Fireblocks:NCW"

const val NAME = "ReactNativeNcwSdk"
const val NAME = "ReactNativeNcwSdk"

private val initializedDevices: MutableSet<String> = HashSet()
}
private val initializedDevices: MutableSet<String> = HashSet()
}
}
26 changes: 25 additions & 1 deletion android/src/oldarch/ReactNativeNcwSdkSpec.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,34 @@ package com.fireblocks.reactnativencwsdk

import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReactContextBaseJavaModule
import com.facebook.react.bridge.ReadableArray
import com.facebook.react.bridge.ReadableMap
import com.facebook.react.bridge.Promise

abstract class ReactNativeNcwSdkSpec internal constructor(context: ReactApplicationContext) :
ReactContextBaseJavaModule(context) {

abstract fun multiply(a: Double, b: Double, promise: Promise)
abstract fun handleResponse(response: ReadableMap, promise: Promise)
abstract fun getPhysicalDeviceId(): String
abstract fun initialize(deviceId: String, promise: Promise)
abstract fun getKeysStatus(deviceId: String, promise: Promise)
abstract fun generateMPCKeys(deviceId: String, algorithms: ReadableArray, promise: Promise)
abstract fun backupKeys(
deviceId: String,
passphrase: String,
passphraseId: String,
promise: Promise
)
abstract fun recoverKeys(deviceId: String, promise: Promise)
abstract fun takeover(deviceId: String, promise: Promise)
abstract fun requestJoinExistingWallet(deviceId: String, promise: Promise)
abstract fun stopJoinWallet(deviceId: String)
abstract fun approveJoinWalletRequest(deviceId: String, requestId: String, promise: Promise)
abstract fun deriveAssetKey(
deviceId: String,
extendedPrivateKey: String,
bip44DerivationParams: ReadableMap
): String?
abstract fun signTransaction(deviceId: String, txId: String, promise: Promise)
abstract fun getTransactionSignatureStatus(deviceId: String, txId: String, promise: Promise)
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fireblocks/react-native-ncw-sdk",
"version": "0.1.5",
"version": "0.1.6",
"description": "NCW SDK Native bridge",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down

0 comments on commit 0bd3b0a

Please sign in to comment.