From 058089b3bf3eb070976182e4ca1aec0cf404a5aa Mon Sep 17 00:00:00 2001 From: Torrey Atcitty Date: Tue, 20 Aug 2024 13:05:29 -0700 Subject: [PATCH] Remove BlockNative as notify API is being deprecated. --- .github/workflows/build-workflow.yml | 1 - README.md | 2 - config/env.js | 4 - config/env/development.json | 3 +- config/env/production.json | 3 +- package.json | 1 - src/elm/Main.elm | 15 +-- src/elm/Port.elm | 8 -- src/js/dapp.js | 1 - src/js/ports.js | 193 +++------------------------ yarn.lock | 9 -- 11 files changed, 22 insertions(+), 218 deletions(-) diff --git a/.github/workflows/build-workflow.yml b/.github/workflows/build-workflow.yml index 125c0bf..ddac4f0 100644 --- a/.github/workflows/build-workflow.yml +++ b/.github/workflows/build-workflow.yml @@ -64,7 +64,6 @@ jobs: run: yarn build env: DATA_PROVIDERS: ${{ secrets.DATA_PROVIDERS }} - BLOCKNATIVE_API_KEY: ${{ secrets.BLOCKNATIVE_API_KEY }} WALLET_CONNECT_PROJECT_ID: ${{ secrets.WALLET_CONNECT_PROJECT_ID }} - name: Archive App diff --git a/README.md b/README.md index 585ff08..51a3072 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,6 @@ The following is an example configuration file: "development": 999 }, "DEFAULT_NETWORK": "mainnet", - "BLOCKNATIVE_API_KEY": "YOUR_BLOCKNATIVE_KEY", "WALLET_CONNECT_PROJECT_ID": "YOUR_WALLET_CONNECT_PROJECT_ID" } ``` @@ -53,7 +52,6 @@ Each of the top level keys have the following functions: - `API_BASE_URL_MAP` - Object mapping of Eth network name as key and value being the desired Compound Api host. This can be left as is. - `DATA_PROVIDERS` - Object mapping of Eth network name as key and value being the url of a corresponding JSON RPC host. This example shows Infura as a sample JSON RPC provider and you can find more information [here](https://infura.io/docs/ethereum). Note: this can be specified by setting in the env var `DATA_PROVIDERS` as JSON (e.g. `export DATA_PROVIDERS='{"rinkeby": "https://infura.io/..."}'`). - `NETWORK_MAP` - Object mapping of Eth network name as key and value being the corresponding NetworkId value. This can be left as is. -- `BLOCKNATIVE_API_KEY` - Blocknative API Key required to track transaction notifications. You can find more information [here](https://docs.blocknative.com/notify). Note: this can be specified by setting the env var `BLOCKNATIVE_API_KEY`. This key is not strictly required (but provides a better user experience). - `WALLET_CONNECT_PROJECT_ID` - Wallect Connect Project Id required to use Wallet Connect as a wallet type in the app. You can find more information [here](https://docs.walletconnect.com/2.0/). Note: this can be specified by setting the env var `WALLET_CONNECT_PROJECT_ID`. This id is not required unless you want to enable wallet connect usage. ## Getting Started diff --git a/config/env.js b/config/env.js index 6356900..e3463d2 100644 --- a/config/env.js +++ b/config/env.js @@ -88,10 +88,6 @@ const envPath = path.join(appDirectory, '/config/env'); const envJson = fs.readFileSync(path.join(envPath, `${CONFIG_ENV}.json`)); const envConfig = JSON.parse(envJson); -if (process.env['BLOCKNATIVE_API_KEY']) { - envConfig.BLOCKNATIVE_API_KEY = process.env['BLOCKNATIVE_API_KEY']; -} - if (process.env['WALLET_CONNECT_PROJECT_ID']) { envConfig.WALLET_CONNECT_PROJECT_ID = process.env['WALLET_CONNECT_PROJECT_ID']; } diff --git a/config/env/development.json b/config/env/development.json index 0b23fe0..2b96481 100644 --- a/config/env/development.json +++ b/config/env/development.json @@ -18,6 +18,5 @@ "kovan": 42, "development": 999 }, - "DEFAULT_NETWORK": "mainnet", - "BLOCKNATIVE_API_KEY": null + "DEFAULT_NETWORK": "mainnet" } diff --git a/config/env/production.json b/config/env/production.json index d5ac06a..81d8a2b 100644 --- a/config/env/production.json +++ b/config/env/production.json @@ -17,6 +17,5 @@ "goerli": 5, "kovan": 42 }, - "DEFAULT_NETWORK": "mainnet", - "BLOCKNATIVE_API_KEY": null + "DEFAULT_NETWORK": "mainnet" } diff --git a/package.json b/package.json index 97c2d50..cb04f27 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,6 @@ "assets-webpack-plugin": "^3.5.1", "autoprefixer": "^9.7.6", "babel-loader": "^8.0.0", - "bnc-sdk": "^3.3.3", "case-sensitive-paths-webpack-plugin": "^2.1.2", "chalk": "^4.0.0", "clean-webpack-plugin": "^3.0.0", diff --git a/src/elm/Main.elm b/src/elm/Main.elm index a65be67..7111db3 100644 --- a/src/elm/Main.elm +++ b/src/elm/Main.elm @@ -41,7 +41,7 @@ import Http import Json.Decode import Json.Encode import Liquidate -import Port exposing (askNetwork, askNewBlock, askSetBlockNativeNetworkPort, giveAccountBalance, giveError, giveNewBlock, setGasPrice, setTitle) +import Port exposing (askNetwork, askNewBlock, giveAccountBalance, giveError, giveNewBlock, setGasPrice, setTitle) import Preferences exposing (PreferencesMsg(..), preferencesInit, preferencesSubscriptions, preferencesUpdate) import Repl import Strings.Translations as Translations @@ -326,7 +326,6 @@ newBlockCmd apiBaseUrlMap maybeNetwork blockNumber previousBlockNumber ({ dataPr _ -> [] - in Cmd.batch <| pageCmds @@ -373,15 +372,9 @@ handleUpdatesFromEthConnectedWallet maybeConfig connectedEthWalletMsg model = else model.voteModel - setBlockNativeCmd = - askSetBlockNativeNetworkPort - { networkId = networkId newNetwork - } - cmd = Cmd.batch - ([ setBlockNativeCmd - , refreshLatestGasPrice model.apiBaseUrlMap newNetwork + ([ refreshLatestGasPrice model.apiBaseUrlMap newNetwork , Cmd.map WrappedTokenMsg newTokenCmd , Cmd.map liquidateTranslator newLiquidateCmd ] @@ -391,6 +384,7 @@ handleUpdatesFromEthConnectedWallet maybeConfig connectedEthWalletMsg model = refreshBlockCmd = if model.network /= Just newNetwork then newBlockCmd model.apiBaseUrlMap (Just newNetwork) blockNumber Nothing model + else Cmd.none in @@ -1117,10 +1111,11 @@ update msg ({ page, configs, apiBaseUrlMap, account, transactionState, bnTransac view : Model -> Html Msg -view ({userLanguage} as model) = +view ({ userLanguage } as model) = Html.div [ id "main" ] (viewFull model) + viewFull : Model -> List (Html Msg) viewFull ({ page, liquidateModel, transactionState, compoundState, tokenState, oracleState, configs, configAbis, network, preferences, account, blockNumber, userLanguage } as model) = let diff --git a/src/elm/Port.elm b/src/elm/Port.elm index b48376a..27af851 100644 --- a/src/elm/Port.elm +++ b/src/elm/Port.elm @@ -1,7 +1,6 @@ port module Port exposing ( askNetwork , askNewBlock - , askSetBlockNativeNetworkPort , encodeParameters , giveAccountBalance , giveEncodedExtrinsic @@ -42,13 +41,6 @@ port setTitle : String -> Cmd msg port giveProviderType : (Int -> msg) -> Sub msg - --- Update BlockNative target network - - -port askSetBlockNativeNetworkPort : { networkId : Int } -> Cmd msg - - port giveAccountBalancePort : (Value -> msg) -> Sub msg diff --git a/src/js/dapp.js b/src/js/dapp.js index 8e636d6..d552089 100644 --- a/src/js/dapp.js +++ b/src/js/dapp.js @@ -127,7 +127,6 @@ window.addEventListener('load', function () { configFiles, configAbiFiles, configNameToAddressMappings, - process.env.BLOCKNATIVE_API_KEY, process.env.WALLET_CONNECT_PROJECT_ID ); }); diff --git a/src/js/ports.js b/src/js/ports.js index adfa23e..9c5dd7e 100644 --- a/src/js/ports.js +++ b/src/js/ports.js @@ -1,6 +1,5 @@ import { Sleuth } from '../../node_modules/@compound-finance/sleuth'; import { StaticJsonRpcProvider } from '../../node_modules/@ethersproject/providers'; -import BlocknativeSdk from '../../node_modules/bnc-sdk'; import BN from '../../node_modules/bn.js'; import connectedWalletPorts from '../../node_modules/compound-components/src/js/sharedEth/connectedWalletPorts'; import EthUtils from '../../node_modules/web3-utils'; @@ -57,7 +56,6 @@ const EXP_SCALE_BN = new BN(10).pow(new BN(18)); // 1e18 used for BN.div const defaultCallParams = { gas: 1.0e10 }; const transactionStorage = trxStorage('transactions'); -const bnTransactionStorage = bnTxStorage('blocknative_transactions'); const preferencesStorage = storage('preferences'); // We wait this amount of milliseconds before informing Elm of a new block @@ -105,24 +103,6 @@ async function getBlockTimestamps(blockNumbers, network) { } } -let blockNativeApiKey; -let blockNativeNetwork = {}; -let blockNative; - -function buildBlockNative(networkId) { - if (blockNativeApiKey) { - if (blockNativeNetwork[networkId]) { - blockNative = blockNativeNetwork[networkId]; - } else { - blockNative = new BlocknativeSdk({ - dappId: blockNativeApiKey, - networkId: networkId, - }); - blockNativeNetwork[networkId] = blockNative; - } - } -} - async function handleReceipt(app, eth, trxHash, blockNumber, receipt, trxNonce) { // Ignore missing receipts or receipts that are beyond our knowledge of the // latest block (this is to provide consistency with the rest of the UI) @@ -486,44 +466,6 @@ function subscribeToStoreTransaction(app, eth) { app.ports.askClearTransactionsPort.subscribe(({}) => { transactionStorage.clear(); }); - - /** - * Block Native storage. We can remove the above ports when we fully migrate to Block Native - */ - // port storeBNTransactionPort : { txModuleId : String, timestamp : Maybe Time.Posix, network : Network, txId : Int, txHash : Maybe Hex, txStatus : String, fromAddress : Address, toAddress : Address, func : String, args : List String } - app.ports.storeBNTransactionPort.subscribe( - ({ txModuleId, timestamp, network, txId, txHash, txStatus, fromAddress, toAddress, func, args }) => { - bnTransactionStorage.put( - txModuleId, - timestamp, - network, - txId, - txHash, - txStatus, - fromAddress, - toAddress, - func, - args - ); - } - ); - - // port storeBNTransactionUpdatePort : { txModuleId : String, txId : Int, txHas : String, txStatus : Int } -> Cmd msg - app.ports.storeBNTransactionUpdatePort.subscribe(({ txModuleId, txId, txHash, txStatus }) => { - bnTransactionStorage.update(txModuleId, txId, txHash, txStatus); - }); - - // port askStoredBNTransactionsPort : {} -> Cmd msg - app.ports.askStoredBNTransactionsPort.subscribe(({}) => { - const transactions = Object.values(bnTransactionStorage.getAll()); - - app.ports.giveStoredBNTransactionsPort.send(transactions); - }); - - // port askClearBNTransactionsPort : {} -> Cmd msg - app.ports.askClearBNTransactionsPort.subscribe(({}) => { - bnTransactionStorage.clear(); - }); } function subscribeToPreferences(app, eth) { @@ -1364,12 +1306,9 @@ function handleTransactionNotification(app, eth, txModule, txId, txHash, status, }); } -function subscribeToEtherPorts(app, eth, blockNativeApiKey) { +function subscribeToEtherPorts(app, eth) { // port etherSendTransactionPort : String -> Encode.Value -> Cmd msg app.ports.etherSendTransactionPort.subscribe(([txModule, txId, { from, to, data, value }]) => { - // Remember value since we could change networks while we're still awaiting results - let txBlockNative = blockNative; - const trxPayload = { from, to, @@ -1387,67 +1326,20 @@ function subscribeToEtherPorts(app, eth, blockNativeApiKey) { web3Eth .sendTransaction(trxPayloadWithGasLimit) .on('transactionHash', (txHash) => { - if (txBlockNative) { - const { emitter } = txBlockNative.transaction(txHash); - - emitter.on('txSpeedUp', (transaction) => { - handleTransactionNotification( - app, - eth, - txModule, - txId, - transaction.originalHash, - 'speedup', - transaction.blockNumber - ); - }); - - emitter.on('txCancel', (transaction) => { - handleTransactionNotification( - app, - eth, - txModule, - txId, - transaction.originalHash, - 'cancel', - transaction.blockNumber - ); - }); - - emitter.on('all', (transaction) => { - handleTransactionNotification( - app, - eth, - txModule, - txId, - transaction.hash, - transaction.status, - transaction.blockNumber - ); - }); - - // port etherTransactionHashPort : (Json.Decode.Value -> msg) -> Sub msg - app.ports.etherTransactionHashPort.send({ - txModule, - txId, - txHash, - }); - } else { - // If no blocknative, then let's try creating a non BN Transaction - // so it can be watched for every new block. - app.ports.giveNewNonBNTrxPort.send({ - txModule, - txId, - txHash: txHash, - }); - - // Finally let's trigger a reject of the BNTransaction so we don't try 2 - // of them. - app.ports.etherTransactionRejectedPort.send({ - txModule, - txId, - }); - } + // If no blocknative, then let's try creating a non BN Transaction + // so it can be watched for every new block. + app.ports.giveNewNonBNTrxPort.send({ + txModule, + txId, + txHash: txHash, + }); + + // Finally let's trigger a reject of the BNTransaction so we don't try 2 + // of them. + app.ports.etherTransactionRejectedPort.send({ + txModule, + txId, + }); }) .catch((e) => { // User denied transaction signature @@ -1471,49 +1363,6 @@ function subscribeToEtherPorts(app, eth, blockNativeApiKey) { // port etherWatchTransactionPort : ( String, Int, String ) -> Encode.Value -> Cmd msg app.ports.etherWatchTransactionPort.subscribe(([txModule, txId, txHash]) => { - if (blockNative) { - const { emitter } = blockNative.transaction(txHash); - - emitter.on('txSpeedUp', (transaction) => { - handleTransactionNotification( - app, - eth, - txModule, - txId, - transaction.originalHash, - 'speedup', - transaction.blockNumber - ); - }); - - emitter.on('txCancel', (transaction) => { - handleTransactionNotification( - app, - eth, - txModule, - txId, - transaction.originalHash, - 'cancel', - transaction.blockNumber - ); - }); - - emitter.on('all', (transaction) => { - handleTransactionNotification( - app, - eth, - txModule, - txId, - transaction.hash, - transaction.status, - transaction.blockNumber - ); - }); - } - - // There is a quick where Block Native does not actually notify us of a final state - // (like confirmed) if the transaction go into that state while we were not actively - // watching it. So let's redundantly ask web3 for the status as well. getTransactionReceipt(eth, txHash) .then((receipt) => { if (!receipt) { @@ -1557,13 +1406,6 @@ function subscribeToFlywheelPorts(app, eth) { }); } -function subscribeToSetBlockNativeNetwork(app, eth) { - // port askSetBlockNativeNetworkPort : { networkId : Int } -> Cmd msg - app.ports.askSetBlockNativeNetworkPort.subscribe(({ networkId }) => { - buildBlockNative(networkId); - }); -} - function subscribe( app, globEthereum, @@ -1574,14 +1416,12 @@ function subscribe( configFiles, configAbiFiles, configNameToAddressMappings, - blockNativeApiKeyInput, walletConnectProjectId ) { const eth = makeEth(dataProviders, networkMap, networkAbiMap, configNameToAddressMappings, defaultNetwork); connectedWalletPorts.subscribe(app, eth, globEthereum, networkMap, defaultNetwork, walletConnectProjectId); subscribeToConsole(app); - subscribeToSetBlockNativeNetwork(app, eth); subscribeToCTokenPorts(app, eth); subscribeToNewBlocks(app, eth); subscribeToCheckTrxStatus(app, eth); @@ -1592,9 +1432,6 @@ function subscribe( subscribeToAdminDashboard(app, eth); subscribeToGovernancePorts(app, eth); subscribeToFlywheelPorts(app, eth); - - // TODO: Do we want to reduce the globalness of these vars? - blockNativeApiKey = blockNativeApiKeyInput; subscribeToEtherPorts(app, eth); } diff --git a/yarn.lock b/yarn.lock index c2a5370..be9c212 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3504,15 +3504,6 @@ bnc-sdk@^2.1.5: crypto-es "^1.2.2" sturdy-websocket "^0.1.12" -bnc-sdk@^3.3.3: - version "3.5.0" - resolved "https://registry.yarnpkg.com/bnc-sdk/-/bnc-sdk-3.5.0.tgz#b863a2d947857d87c56d53261bd43529f1a5c03e" - integrity sha512-4CSon8xRTjtD7YOUDJcyqZ/bKCNNwDc4sOPq6O19AlolYTsbbVvh+p5EOmYqL4Re30hI3lKQxN4sh12A6VnAPQ== - dependencies: - crypto-es "^1.2.2" - rxjs "^6.6.3" - sturdy-websocket "^0.1.12" - body-parser@1.19.0: version "1.19.0" resolved "https://registry.yarnpkg.com/body-parser/-/body-parser-1.19.0.tgz#96b2709e57c9c4e09a6fd66a8fd979844f69f08a"