Skip to content

Commit

Permalink
Merge pull request #297 from EdgeApp/william/native-build
Browse files Browse the repository at this point in the history
Add native build
  • Loading branch information
swansontec authored Oct 24, 2023
2 parents 03f6a1d + e27e10f commit 827004c
Show file tree
Hide file tree
Showing 51 changed files with 818 additions and 2,345 deletions.
6 changes: 3 additions & 3 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/lib/
/node_modules/
/.nyc_output/
/android/src/main/assets/edge-exchange-plugins/
/coverage/
/dist/
/lib/
19 changes: 13 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
# Javascript:
lib/
# Build output:
/.nyc_output/
/android/.gradle
/android/*.jar
/android/src/main/assets/edge-exchange-plugins/
/coverage/
/dist/
/lib/

# Package managers:
node_modules/
npm-debug.log
package-lock.json
yarn-error.log

# Editors:
.DS_Store
.idea/
.vscode/

# Test results:
.nyc_output/
/coverage/
16 changes: 0 additions & 16 deletions .mocharc.json

This file was deleted.

7 changes: 3 additions & 4 deletions .nycrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"include": ["src/**/*.ts"],
"extension": [".ts"],
"require": ["sucrase/register"],
"all": true
}
"include": ["src/**/*.ts"],
"require": ["sucrase/register"]
}
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

- changed: Simplify our React Native integration.
- removed: Delete all rate plugins.

## 0.22.0 (2023-10-24)

- changed: Thorchain quotes to estimate rate
Expand Down
72 changes: 52 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,63 @@

This library exports a collection of exchange-rate & swap plugins for use with [`edge-core-js`](https://github.com/EdgeApp/edge-core-js).

Use it like this:
Please see [index.js](./src/index.js) for the list of plugins in this repo. These are compatible with edge-core-js v0.19.31 or later.

## Installing

Fist, add this library to your project:

```sh
yarn add edge-exchange-plugins
```

### Node.js

For Node.js, you should call `addEdgeCorePlugins` to register these plugins with edge-core-js:

```js
import {
addEdgeCorePlugins,
lockEdgeCorePlugins,
makeEdgeContext
} from 'edge-core-js'
import exchangePlugins from 'edge-exchange-plugins'

addEdgeCorePlugins(exchangePlugins)
const { addEdgeCorePlugins, lockEdgeCorePlugins } = require('edge-core-js')
const plugins = require('edge-exchange-plugins')

addEdgeCorePlugins(plugins)

// Once you are done adding plugins, call this:
lockEdgeCorePlugins()
```

makeEdgeContext({
apiKey: '',
appId: '',
plugins: {
// Plugin names from edge-exchange-plugins:
coinbase: true,
shapeshift: true
}
You can also add plugins individually if you want to be more picky:

```js
addEdgeCorePlugins({
thorchain: plugins.thorchain
})
```

### Browser

The bundle located in `dist/edge-exchange-plugins.js` will automatically register itself with edge-core-js. Just serve the entire `dist` directory along with your app, and then load the script:

```html
<script src='https://example.com/app/dist/edge-exchange-plugins.js'>
```
Please see [index.js](./src/index.js) for the list of plugins in this repo.
If you want to debug this project, run `yarn start` to start a Webpack server,
and then adjust your script URL to http://localhost:8083/edge-exchange-plugins.js.
### React Native
This package will automatically install itself using React Native autolinking. To integrate the plugins with edge-core-js, add its URI to the context component:
```jsx
import { pluginUri } from 'edge-exchange-plugins'
<MakeEdgeContext
pluginUris={[pluginUri]}
// Plus other props as required...
/>
```
To debug this project, run `yarn start` to start a Webpack server, and then use `debugUri` instead of `pluginUri`.
## edge-react-gui
Expand All @@ -39,16 +70,17 @@ To test your exchange plugin, build the full application at [`edge-react-gui`](h
Clone this repo as a peer in the same directory as `edge-react-gui`. Then run
```
```sh
yarn
yarn prepare
```
From within the `edge-react-gui`
```
```sh
yarn updot edge-exchange-plugins
yarn prepare
yarn prepare.ios # For iPhone development
```
Make appropriate changes to `edge-react-gui` to include your plugin. Search `edge-react-gui` for the string `changelly` and make similar changes for your plugin.
Expand Down
34 changes: 34 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
buildscript {
repositories {
google()
mavenCentral()
}

dependencies {
classpath "com.android.tools.build:gradle:7.3.1"
}
}

apply plugin: 'com.android.library'

def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

android {
compileSdkVersion safeExtGet('compileSdkVersion', 28)
defaultConfig {
minSdkVersion safeExtGet('minSdkVersion', 19)
targetSdkVersion safeExtGet('targetSdkVersion', 27)
}
lintOptions {
abortOnError false
}
}

repositories {
}

dependencies {
implementation 'com.facebook.react:react-native:+'
}
19 changes: 19 additions & 0 deletions android/format-java.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env sh

here=$(dirname $0)

formatJava() {
tool="google-java-format-1.7-all-deps.jar"
url="https://github.com/google/google-java-format/releases/download/google-java-format-1.7/$tool"
jar="$here/$tool"

# If the tool is missing, grab it from GitHub:
if [ ! -e "$jar" ]; then
curl -L -o "$jar" "$url"
fi

echo $(find "$here/src" -name "*.java")
java -jar "$jar" --replace $(find "$here/src" -name "*.java")
}

formatJava
3 changes: 3 additions & 0 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="app.edge.reactnative.exchange">
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package app.edge.reactnative.exchange;

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import java.util.HashMap;
import java.util.Map;

public class EdgeExchangePluginsModule extends ReactContextBaseJavaModule {
EdgeExchangePluginsModule(ReactApplicationContext context) {
super(context);
}

@Override
public Map<String, Object> getConstants() {
final Map<String, Object> constants = new HashMap<>();
constants.put(
"sourceUri",
"file:///android_asset/edge-exchange-plugins/edge-exchange-plugins.js");
return constants;
}

@Override
public String getName() {
return "EdgeExchangePluginsModule";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package app.edge.reactnative.exchange;

import androidx.annotation.NonNull;
import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;
import java.util.Collections;
import java.util.List;

public class EdgeExchangePluginsPackage implements ReactPackage {
@NonNull
@Override
public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) {
return Collections.<NativeModule>singletonList(
new EdgeExchangePluginsModule(reactContext));
}

@NonNull
@Override
public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) {
return Collections.emptyList();
}
}
18 changes: 18 additions & 0 deletions edge-exchange-plugins.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { EdgeCorePluginOptions, EdgeCurrencyPlugin } from 'edge-core-js/types'

/* Debug-mode URI to use on React Native. */
export const debugUri: string

/* Regular URI to use on React Native. */
export const pluginUri: string

type EdgeCorePluginFactory = (env: EdgeCorePluginOptions) => EdgeCurrencyPlugin

/**
* The Node.js default export.
*/
declare const plugins: {
[pluginId: string]: EdgeCorePluginFactory
}

export default plugins
28 changes: 28 additions & 0 deletions edge-exchange-plugins.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require "json"

package = JSON.parse(File.read(File.join(__dir__, "package.json")))

Pod::Spec.new do |s|
s.name = package['name']
s.version = package['version']
s.summary = package['description']
s.homepage = package['homepage']
s.license = package['license']
s.authors = package['author']

s.platform = :ios, "9.0"
s.requires_arc = true
s.source = {
:git => "https://github.com/EdgeApp/edge-exchange-plugins.git",
:tag => "v#{s.version}"
}
s.source_files =
"ios/EdgeExchangePluginsModule.swift",
"ios/EdgeExchangePluginsModule.m"

s.resource_bundles = {
"edge-exchange-plugins" => "android/src/main/assets/edge-exchange-plugins/*.js"
}

s.dependency "React-Core"
end
4 changes: 4 additions & 0 deletions ios/EdgeExchangePluginsModule.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#import <React/RCTBridgeModule.h>

@interface RCT_EXTERN_MODULE(EdgeExchangePluginsModule, NSObject)
@end
20 changes: 20 additions & 0 deletions ios/EdgeExchangePluginsModule.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@objc(EdgeExchangePluginsModule) class EdgeExchangePluginsModule: NSObject {
@objc static func requiresMainQueueSetup() -> Bool { return false }

@objc func constantsToExport() -> NSDictionary {
return ["sourceUri": sourceUri() ?? ""]
}

func sourceUri() -> String? {
if let bundleUrl = Bundle.main.url(
forResource: "edge-exchange-plugins",
withExtension: "bundle"
),
let bundle = Bundle(url: bundleUrl),
let script = bundle.url(forResource: "edge-exchange-plugins", withExtension: "js")
{
return script.absoluteString
}
return nil
}
}
1 change: 1 addition & 0 deletions ios/edge-exchange-plugins/project.pbxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Placeholder so react-native autolinking can find us.
Loading

0 comments on commit 827004c

Please sign in to comment.