From 670d9648cdf3d5253b315d02b9c02e6990b1e4ff Mon Sep 17 00:00:00 2001 From: William Swanson Date: Thu, 19 Oct 2023 15:15:14 -0700 Subject: [PATCH 1/4] Downgrade to TypeScript v4.4 This is the last version of TypeScript tha is compatible with our lint plugins. --- package.json | 2 +- src/rate/currencyconverterapi.ts | 2 +- src/swap/exolix.ts | 3 ++- yarn.lock | 8 ++++---- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 16a79ebe..6300f5d4 100644 --- a/package.json +++ b/package.json @@ -100,7 +100,7 @@ "rimraf": "^2.6.2", "stream-browserify": "^3.0.0", "sucrase": "^3.9.5", - "typescript": "^4.1.2", + "typescript": "~4.4.4", "webpack": "^5.28.0", "webpack-cli": "^4.6.0" } diff --git a/src/rate/currencyconverterapi.ts b/src/rate/currencyconverterapi.ts index 18702259..7ea1a72a 100644 --- a/src/rate/currencyconverterapi.ts +++ b/src/rate/currencyconverterapi.ts @@ -58,7 +58,7 @@ export function makeCurrencyconverterapiPlugin( const { status, error, ...rest } = asCurrencyConverterResponse( await response.json() ) - const rates: { [cc: string]: number } = rest + const rates: { [cc: string]: number } = rest as {} if ( (status != null && status !== 200) || (error != null && error !== '') || diff --git a/src/swap/exolix.ts b/src/swap/exolix.ts index 7dc374a9..57f28cf6 100644 --- a/src/swap/exolix.ts +++ b/src/swap/exolix.ts @@ -9,6 +9,7 @@ import { } from 'cleaners' import { EdgeCorePluginOptions, + EdgeFetchResponse, EdgeSpendInfo, EdgeSwapInfo, EdgeSwapPlugin, @@ -102,7 +103,7 @@ export function makeExolixPlugin(opts: EdgeCorePluginOptions): EdgeSwapPlugin { Authorization: `${apiKey}` } - let response: Awaited> + let response: EdgeFetchResponse if (method === 'POST') { const body = JSON.stringify(params) diff --git a/yarn.lock b/yarn.lock index e0fc043f..2809aed0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6061,10 +6061,10 @@ typeforce@^1.11.5: resolved "https://registry.yarnpkg.com/typeforce/-/typeforce-1.18.0.tgz#d7416a2c5845e085034d70fcc5b6cc4a90edbfdc" integrity sha512-7uc1O8h1M1g0rArakJdf0uLRSSgFcYexrVoKo+bzJd32gd4gDy2L/Z+8/FjPnU9ydY3pEnVPtr9FyscYY60K1g== -typescript@^4.1.2: - version "4.8.2" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.8.2.tgz#e3b33d5ccfb5914e4eeab6699cf208adee3fd790" - integrity sha512-C0I1UsrrDHo2fYI5oaCGbSejwX4ch+9Y5jTQELvovfmFkK3HHSZJB8MSJcWLmCUBzQBchCrZ9rMRV6GuNrvGtw== +typescript@~4.4.0: + version "4.4.4" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.4.4.tgz#2cd01a1a1f160704d3101fd5a58ff0f9fcb8030c" + integrity sha512-DqGhF5IKoBl8WNf8C1gu8q0xZSInh9j1kJJMqT3a94w1JzVaBU4EXOSMrz9yDqMT0xt3selp83fuFMQ0uzv6qA== unbox-primitive@^1.0.2: version "1.0.2" From 4e381aa004c67c0fdcc9b7ab12a139ec66bce957 Mon Sep 17 00:00:00 2001 From: William Swanson Date: Thu, 19 Oct 2023 15:23:13 -0700 Subject: [PATCH 2/4] Move swapHelpers to the right folder --- src/swap/changehero.ts | 2 +- src/swap/changenow.ts | 2 +- src/swap/defi/lifi.ts | 4 ++-- src/swap/defi/thorchain.ts | 2 +- src/swap/defi/thorchainDa.ts | 2 +- src/swap/defi/uni-v2-based/plugins/spookySwap.ts | 2 +- src/swap/defi/uni-v2-based/plugins/tombSwap.ts | 2 +- src/swap/defi/uni-v2-based/plugins/velodrome.ts | 2 +- src/swap/defi/xrpDex.ts | 2 +- src/swap/exolix.ts | 2 +- src/swap/godex.ts | 2 +- src/swap/letsexchange.ts | 2 +- src/swap/sideshift.ts | 2 +- src/swap/swapuz.ts | 4 ++-- src/swap/transfer.ts | 2 +- src/{swap-helpers.ts => util/swapHelpers.ts} | 4 ++-- 16 files changed, 19 insertions(+), 19 deletions(-) rename src/{swap-helpers.ts => util/swapHelpers.ts} (98%) diff --git a/src/swap/changehero.ts b/src/swap/changehero.ts index b4c43b48..e84ad8b0 100644 --- a/src/swap/changehero.ts +++ b/src/swap/changehero.ts @@ -26,7 +26,7 @@ import { InvalidCurrencyCodes, makeSwapPluginQuote, SwapOrder -} from '../swap-helpers' +} from '../util/swapHelpers' import { convertRequest, getAddress } from '../util/utils' import { EdgeSwapRequestPlugin, StringMap } from './types' diff --git a/src/swap/changenow.ts b/src/swap/changenow.ts index 21e897e7..cd3d13a7 100644 --- a/src/swap/changenow.ts +++ b/src/swap/changenow.ts @@ -28,7 +28,7 @@ import { InvalidCurrencyCodes, makeSwapPluginQuote, SwapOrder -} from '../swap-helpers' +} from '../util/swapHelpers' import { convertRequest, getAddress } from '../util/utils' import { EdgeSwapRequestPlugin } from './types' const pluginId = 'changenow' diff --git a/src/swap/defi/lifi.ts b/src/swap/defi/lifi.ts index ba39ecaf..826e61b6 100644 --- a/src/swap/defi/lifi.ts +++ b/src/swap/defi/lifi.ts @@ -11,14 +11,14 @@ import { SwapCurrencyError } from 'edge-core-js/types' +import { div18 } from '../../util/biggystringplus' import { checkInvalidCodes, getMaxSwappable, InvalidCurrencyCodes, makeSwapPluginQuote, SwapOrder -} from '../../swap-helpers' -import { div18 } from '../../util/biggystringplus' +} from '../../util/swapHelpers' import { convertRequest, fetchInfo, diff --git a/src/swap/defi/thorchain.ts b/src/swap/defi/thorchain.ts index 17ba4605..0fa56e7f 100644 --- a/src/swap/defi/thorchain.ts +++ b/src/swap/defi/thorchain.ts @@ -29,7 +29,7 @@ import { isLikeKind, makeSwapPluginQuote, SwapOrder -} from '../../swap-helpers' +} from '../../util/swapHelpers' import { convertRequest, fetchInfo, diff --git a/src/swap/defi/thorchainDa.ts b/src/swap/defi/thorchainDa.ts index c2b0de5c..43c5c965 100644 --- a/src/swap/defi/thorchainDa.ts +++ b/src/swap/defi/thorchainDa.ts @@ -28,7 +28,7 @@ import { getTokenId, makeSwapPluginQuote, SwapOrder -} from '../../swap-helpers' +} from '../../util/swapHelpers' import { convertRequest, fetchInfo, diff --git a/src/swap/defi/uni-v2-based/plugins/spookySwap.ts b/src/swap/defi/uni-v2-based/plugins/spookySwap.ts index 4f63c150..c2610499 100644 --- a/src/swap/defi/uni-v2-based/plugins/spookySwap.ts +++ b/src/swap/defi/uni-v2-based/plugins/spookySwap.ts @@ -16,7 +16,7 @@ import { getMaxSwappable, makeSwapPluginQuote, SwapOrder -} from '../../../../swap-helpers' +} from '../../../../util/swapHelpers' import { convertRequest } from '../../../../util/utils' import { EdgeSwapRequestPlugin } from '../../../types' import { getInOutTokenAddresses, InOutTokenAddresses } from '../../defiUtils' diff --git a/src/swap/defi/uni-v2-based/plugins/tombSwap.ts b/src/swap/defi/uni-v2-based/plugins/tombSwap.ts index 56de5858..432d5f4a 100644 --- a/src/swap/defi/uni-v2-based/plugins/tombSwap.ts +++ b/src/swap/defi/uni-v2-based/plugins/tombSwap.ts @@ -16,7 +16,7 @@ import { getMaxSwappable, makeSwapPluginQuote, SwapOrder -} from '../../../../swap-helpers' +} from '../../../../util/swapHelpers' import { convertRequest } from '../../../../util/utils' import { EdgeSwapRequestPlugin } from '../../../types' import { getInOutTokenAddresses, InOutTokenAddresses } from '../../defiUtils' diff --git a/src/swap/defi/uni-v2-based/plugins/velodrome.ts b/src/swap/defi/uni-v2-based/plugins/velodrome.ts index a2c3945f..950e08b0 100644 --- a/src/swap/defi/uni-v2-based/plugins/velodrome.ts +++ b/src/swap/defi/uni-v2-based/plugins/velodrome.ts @@ -15,7 +15,7 @@ import { getMaxSwappable, makeSwapPluginQuote, SwapOrder -} from '../../../../swap-helpers' +} from '../../../../util/swapHelpers' import { convertRequest } from '../../../../util/utils' import { EdgeSwapRequestPlugin } from '../../../types' import VELODROME_V1_ROUTER_ABI from '../../abi/VELODROME_V1_ROUTER_ABI' diff --git a/src/swap/defi/xrpDex.ts b/src/swap/defi/xrpDex.ts index a6867654..7d30b99a 100644 --- a/src/swap/defi/xrpDex.ts +++ b/src/swap/defi/xrpDex.ts @@ -12,7 +12,7 @@ import { } from 'edge-core-js/types' import { Client } from 'xrpl' -import { makeSwapPluginQuote, SwapOrder } from '../../swap-helpers' +import { makeSwapPluginQuote, SwapOrder } from '../../util/swapHelpers' import { convertRequest, fetchInfo, diff --git a/src/swap/exolix.ts b/src/swap/exolix.ts index 57f28cf6..c6b905ba 100644 --- a/src/swap/exolix.ts +++ b/src/swap/exolix.ts @@ -26,7 +26,7 @@ import { InvalidCurrencyCodes, makeSwapPluginQuote, SwapOrder -} from '../swap-helpers' +} from '../util/swapHelpers' import { convertRequest, getAddress } from '../util/utils' import { EdgeSwapRequestPlugin } from './types' diff --git a/src/swap/godex.ts b/src/swap/godex.ts index 67efc058..bd0363c2 100644 --- a/src/swap/godex.ts +++ b/src/swap/godex.ts @@ -27,7 +27,7 @@ import { InvalidCurrencyCodes, makeSwapPluginQuote, SwapOrder -} from '../swap-helpers' +} from '../util/swapHelpers' import { convertRequest, getAddress } from '../util/utils' import { asNumberString, EdgeSwapRequestPlugin } from './types' diff --git a/src/swap/letsexchange.ts b/src/swap/letsexchange.ts index a21633df..6621f583 100644 --- a/src/swap/letsexchange.ts +++ b/src/swap/letsexchange.ts @@ -19,7 +19,7 @@ import { InvalidCurrencyCodes, makeSwapPluginQuote, SwapOrder -} from '../swap-helpers' +} from '../util/swapHelpers' import { convertRequest, getAddress } from '../util/utils' import { asOptionalBlank } from './changenow' import { asNumberString, EdgeSwapRequestPlugin } from './types' diff --git a/src/swap/sideshift.ts b/src/swap/sideshift.ts index 321f08dc..d2dd9b68 100644 --- a/src/swap/sideshift.ts +++ b/src/swap/sideshift.ts @@ -22,7 +22,7 @@ import { InvalidCurrencyCodes, makeSwapPluginQuote, SwapOrder -} from '../swap-helpers' +} from '../util/swapHelpers' import { convertRequest, getAddress } from '../util/utils' import { EdgeSwapRequestPlugin } from './types' diff --git a/src/swap/swapuz.ts b/src/swap/swapuz.ts index db4e55ae..4d8825c0 100644 --- a/src/swap/swapuz.ts +++ b/src/swap/swapuz.ts @@ -18,6 +18,7 @@ import { SwapCurrencyError } from 'edge-core-js/types' +import { div18 } from '../util/biggystringplus' import { checkInvalidCodes, ensureInFuture, @@ -27,8 +28,7 @@ import { isLikeKind, makeSwapPluginQuote, SwapOrder -} from '../swap-helpers' -import { div18 } from '../util/biggystringplus' +} from '../util/swapHelpers' import { convertRequest, getAddress } from '../util/utils' import { EdgeSwapRequestPlugin } from './types' diff --git a/src/swap/transfer.ts b/src/swap/transfer.ts index 5e6c9900..aafb06ae 100644 --- a/src/swap/transfer.ts +++ b/src/swap/transfer.ts @@ -11,7 +11,7 @@ import { getMaxSwappable, makeSwapPluginQuote, SwapOrder -} from '../swap-helpers' +} from '../util/swapHelpers' import { convertRequest } from '../util/utils' import { EdgeSwapRequestPlugin } from './types' diff --git a/src/swap-helpers.ts b/src/util/swapHelpers.ts similarity index 98% rename from src/swap-helpers.ts rename to src/util/swapHelpers.ts index 17b0200f..08150161 100644 --- a/src/swap-helpers.ts +++ b/src/util/swapHelpers.ts @@ -13,8 +13,8 @@ import { SwapCurrencyError } from 'edge-core-js/types' -import { MakeTxParams } from './swap/defi/xrp/xrpDexTypes' -import { EdgeSwapRequestPlugin } from './swap/types' +import { MakeTxParams } from '../swap/defi/xrp/xrpDexTypes' +import { EdgeSwapRequestPlugin } from '../swap/types' const likeKindAssets = [ ['BTC', 'WBTC', 'SBTC', 'RBTC'], From 5a82e3e5edaa29172d40d449969b7a5c37e553cf Mon Sep 17 00:00:00 2001 From: William Swanson Date: Thu, 19 Oct 2023 11:41:06 -0700 Subject: [PATCH 3/4] Simplify our React Native integration --- .eslintignore | 6 +- .gitignore | 19 +- .mocharc.json | 16 - .nycrc.json | 7 +- CHANGELOG.md | 2 + README.md | 72 +- android/build.gradle | 34 + android/format-java.sh | 19 + android/src/main/AndroidManifest.xml | 3 + .../exchange/EdgeExchangePluginsModule.java | 26 + .../exchange/EdgeExchangePluginsPackage.java | 24 + edge-exchange-plugins.d.ts | 18 + edge-exchange-plugins.podspec | 28 + ios/EdgeExchangePluginsModule.m | 4 + ios/EdgeExchangePluginsModule.swift | 20 + ios/edge-exchange-plugins/project.pbxproj | 1 + package.json | 57 +- src/declare-modules.d.ts | 12 +- src/index.ts | 16 +- src/react-native.ts | 13 +- tsconfig.json | 15 +- webpack.config.js | 67 +- yarn.lock | 1594 +++++------------ 23 files changed, 792 insertions(+), 1281 deletions(-) delete mode 100644 .mocharc.json create mode 100644 android/build.gradle create mode 100644 android/format-java.sh create mode 100644 android/src/main/AndroidManifest.xml create mode 100644 android/src/main/java/app/edge/reactnative/exchange/EdgeExchangePluginsModule.java create mode 100644 android/src/main/java/app/edge/reactnative/exchange/EdgeExchangePluginsPackage.java create mode 100644 edge-exchange-plugins.d.ts create mode 100644 edge-exchange-plugins.podspec create mode 100644 ios/EdgeExchangePluginsModule.m create mode 100644 ios/EdgeExchangePluginsModule.swift create mode 100644 ios/edge-exchange-plugins/project.pbxproj diff --git a/.eslintignore b/.eslintignore index a6fc364f..a8ef954b 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,4 +1,4 @@ -/lib/ -/node_modules/ -/.nyc_output/ +/android/src/main/assets/edge-exchange-plugins/ /coverage/ +/dist/ +/lib/ diff --git a/.gitignore b/.gitignore index 64d2d58e..5c246c11 100644 --- a/.gitignore +++ b/.gitignore @@ -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/ diff --git a/.mocharc.json b/.mocharc.json deleted file mode 100644 index 1e6cb659..00000000 --- a/.mocharc.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "extension": ["ts"], - "spec": "test/**/*.spec.ts", - "require": "sucrase/register", - "colors": true, - "reporter":"mocha-multi-reporters", - "reporterOption": "configFile=.mocharc.json", - "reporterEnabled": "mochawesome,mocha-junit-reporter", - "mochaJunitReporterReporterOptions": { - "mochaFile": "./coverage/junit.xml" - }, - "mochawesomeReporterOptions": { - "reportDir": "coverage", - "reportName": "mochawesome" - } -} diff --git a/.nycrc.json b/.nycrc.json index b0feb5d4..d72f9809 100644 --- a/.nycrc.json +++ b/.nycrc.json @@ -1,6 +1,5 @@ { - "include": ["src/**/*.ts"], "extension": [".ts"], - "require": ["sucrase/register"], - "all": true -} \ No newline at end of file + "include": ["src/**/*.ts"], + "require": ["sucrase/register"] +} diff --git a/CHANGELOG.md b/CHANGELOG.md index ed4715a0..72bf4a23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- changed: Simplify our React Native integration. + ## 0.22.0 (2023-10-24) - changed: Thorchain quotes to estimate rate diff --git a/README.md b/README.md index 6a6a1fb1..5fc32a70 100644 --- a/README.md +++ b/README.md @@ -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 +