diff --git a/__tests__/actions/authActions.test.js b/__tests__/actions/authActions.test.js
index dc7f73c89..ffac195f0 100644
--- a/__tests__/actions/authActions.test.js
+++ b/__tests__/actions/authActions.test.js
@@ -1,5 +1,6 @@
import { wifLoginActions } from '../../app/actions/authActions'
+jest.setTimeout(10000)
describe('authActions', () => {
describe('wifLoginActions', () => {
describe('call', () => {
diff --git a/__tests__/actions/blockHeightActions.test.js b/__tests__/actions/blockHeightActions.test.js
index 0c49157f4..cc19d6a21 100644
--- a/__tests__/actions/blockHeightActions.test.js
+++ b/__tests__/actions/blockHeightActions.test.js
@@ -1,4 +1,4 @@
-import { rpc } from '@cityofzion/neon-js'
+import { rpc } from '@cityofzion/neon-js-legacy'
import main, {
blockHeightActions,
diff --git a/__tests__/actions/claimsActions.test.js b/__tests__/actions/claimsActions.test.js
index 6c93e7364..86b2b529b 100644
--- a/__tests__/actions/claimsActions.test.js
+++ b/__tests__/actions/claimsActions.test.js
@@ -1,5 +1,5 @@
/* eslint-disable */
-import { api, u } from '@cityofzion/neon-js'
+import { api, u } from '@cityofzion/neon-js-legacy'
import claimsActions from '../../app/actions/claimsActions'
import { mockPromiseResolved } from '../testHelpers'
diff --git a/__tests__/actions/nodeStorageActions.test.js b/__tests__/actions/nodeStorageActions.test.js
index 00fb3e678..ab396f297 100644
--- a/__tests__/actions/nodeStorageActions.test.js
+++ b/__tests__/actions/nodeStorageActions.test.js
@@ -1,4 +1,4 @@
-import { api } from '@cityofzion/neon-js'
+import { api } from '@cityofzion/neon-js-legacy'
import nock from 'nock'
import { ipcRenderer } from 'electron'
diff --git a/__tests__/components/Logout.test.js b/__tests__/components/Logout.test.js
index 6a5c71c78..0d459b9e7 100644
--- a/__tests__/components/Logout.test.js
+++ b/__tests__/components/Logout.test.js
@@ -2,6 +2,8 @@ import React from 'react'
import { shallow } from 'enzyme'
import Logout from '../../app/containers/App/Sidebar/Logout/Logout'
+import { WalletConnectWalletProvider } from '@cityofzion/wallet-connect-sdk-wallet-react'
+import { walletConnectOptions } from '../../app/util/walletConnect'
describe('Logout', () => {
const logout = jest.fn()
diff --git a/__tests__/setupTests.js b/__tests__/setupTests.js
index a873322e0..17d719d8a 100644
--- a/__tests__/setupTests.js
+++ b/__tests__/setupTests.js
@@ -2,7 +2,7 @@ import 'raf/polyfill'
import { configure } from 'enzyme'
import Adapter from '@cfaester/enzyme-adapter-react-18'
import nock from 'nock'
-import { api } from '@cityofzion/neon-js'
+import { api } from '@cityofzion/neon-js-legacy'
import { TextEncoder, TextDecoder } from 'util'
global.TextEncoder = TextEncoder
diff --git a/app/actions/authActions.js b/app/actions/authActions.js
index 94260224a..9a4474b54 100644
--- a/app/actions/authActions.js
+++ b/app/actions/authActions.js
@@ -1,6 +1,6 @@
// @flow
-import { wallet } from '@cityofzion/neon-js'
-import { wallet as n3Wallet } from '@cityofzion/neon-js-next'
+import { wallet } from '@cityofzion/neon-js-legacy'
+import { wallet as n3Wallet } from '@cityofzion/neon-js'
import { noop } from 'lodash-es'
import { createActions } from 'spunky'
import dns from 'dns'
diff --git a/app/actions/balancesActions.js b/app/actions/balancesActions.js
index 0f151c863..783fc4cb5 100644
--- a/app/actions/balancesActions.js
+++ b/app/actions/balancesActions.js
@@ -1,6 +1,6 @@
// @flow
-import { api, u, rpc, sc, wallet } from '@cityofzion/neon-js'
-import { rpc as n3Rpc } from '@cityofzion/neon-js-next'
+import { api, u, rpc, sc, wallet } from '@cityofzion/neon-js-legacy'
+import { rpc as n3Rpc } from '@cityofzion/neon-js'
import { extend, isEmpty, get } from 'lodash-es'
import { createActions } from 'spunky'
import { Howl } from 'howler'
diff --git a/app/actions/blockHeightActions.js b/app/actions/blockHeightActions.js
index 245af1eac..5edfa7dcf 100644
--- a/app/actions/blockHeightActions.js
+++ b/app/actions/blockHeightActions.js
@@ -1,5 +1,5 @@
// @flow
-import { rpc } from '@cityofzion/neon-js'
+import { rpc } from '@cityofzion/neon-js-legacy'
import { createActions } from 'spunky'
import { isEmpty } from 'lodash-es'
import { getNode, getRPCEndpoint } from './nodeStorageActions'
diff --git a/app/actions/claimsActions.js b/app/actions/claimsActions.js
index 7010a128d..880e0188c 100644
--- a/app/actions/claimsActions.js
+++ b/app/actions/claimsActions.js
@@ -1,6 +1,6 @@
// @flow
import { api } from '@cityofzion/neon-js-legacy-latest'
-import { rpc as n3Rpc, u as n3U } from '@cityofzion/neon-js-next'
+import { rpc as n3Rpc, u as n3U } from '@cityofzion/neon-js'
import { createActions } from 'spunky'
import { getNode, getRPCEndpoint } from './nodeStorageActions'
diff --git a/app/actions/icoTokensActions.js b/app/actions/icoTokensActions.js
index 61b9633c5..21f06dddb 100644
--- a/app/actions/icoTokensActions.js
+++ b/app/actions/icoTokensActions.js
@@ -1,5 +1,5 @@
// @flow
-import { api } from '@cityofzion/neon-js'
+import { api } from '@cityofzion/neon-js-legacy'
import { createActions } from 'spunky'
import { getNode, getRPCEndpoint } from './nodeStorageActions'
diff --git a/app/actions/nftActions.js b/app/actions/nftActions.js
index 1b8ac8365..521b1d8d6 100644
--- a/app/actions/nftActions.js
+++ b/app/actions/nftActions.js
@@ -1,8 +1,8 @@
// @flow
import { createActions } from 'spunky'
import axios from 'axios'
-import { rpc } from '@cityofzion/neon-js'
-import { rpc as n3Rpc } from '@cityofzion/neon-js-next'
+import { rpc } from '@cityofzion/neon-js-legacy'
+import { rpc as n3Rpc } from '@cityofzion/neon-js'
import { getSettings } from './settingsActions'
import { getNode, getRPCEndpoint } from './nodeStorageActions'
diff --git a/app/actions/nodeNetworkActions.js b/app/actions/nodeNetworkActions.js
index 68669b710..257190a54 100644
--- a/app/actions/nodeNetworkActions.js
+++ b/app/actions/nodeNetworkActions.js
@@ -1,5 +1,5 @@
// @flow
-import { rpc, settings } from '@cityofzion/neon-js'
+import { rpc, settings } from '@cityofzion/neon-js-legacy'
import { createActions } from 'spunky'
import {
diff --git a/app/actions/nodeStorageActions.js b/app/actions/nodeStorageActions.js
index 329cc708a..24f1770bc 100644
--- a/app/actions/nodeStorageActions.js
+++ b/app/actions/nodeStorageActions.js
@@ -1,7 +1,7 @@
// @flow
import { createActions } from 'spunky'
import { random, get, compact } from 'lodash-es'
-import { rpc, api, settings } from '@cityofzion/neon-js'
+import { rpc, api, settings } from '@cityofzion/neon-js-legacy'
import { getStorage, setStorage } from '../core/storage'
import {
diff --git a/app/actions/pendingTransactionActions.js b/app/actions/pendingTransactionActions.js
index 827762615..d1825d61e 100644
--- a/app/actions/pendingTransactionActions.js
+++ b/app/actions/pendingTransactionActions.js
@@ -1,6 +1,6 @@
// @flow
import { createActions } from 'spunky'
-import Neon, { rpc } from '@cityofzion/neon-js'
+import Neon, { rpc } from '@cityofzion/neon-js-legacy'
import { isEmpty } from 'lodash-es'
import { toBigNumber } from '../core/math'
diff --git a/app/actions/transactionHistoryActions.js b/app/actions/transactionHistoryActions.js
index 255a71d74..6a4788293 100644
--- a/app/actions/transactionHistoryActions.js
+++ b/app/actions/transactionHistoryActions.js
@@ -1,7 +1,7 @@
// @flow
import { NeoLegacyREST, NeoRest } from '@cityofzion/dora-ts/dist/api'
import { createActions } from 'spunky'
-import { rpc as n3Rpc, sc, u } from '@cityofzion/neon-js-next'
+import { rpc as n3Rpc, sc, u } from '@cityofzion/neon-js'
import axios from 'axios'
import { TX_TYPES } from '../core/constants'
diff --git a/app/actions/voteActions.js b/app/actions/voteActions.js
index 72e940d3d..d26c94c03 100644
--- a/app/actions/voteActions.js
+++ b/app/actions/voteActions.js
@@ -1,5 +1,5 @@
// @flow
-import { api, rpc } from '@cityofzion/neon-js'
+import { api, rpc } from '@cityofzion/neon-js-legacy'
import { createActions } from 'spunky'
import { getNetworkById } from '../core/deprecated'
diff --git a/app/components/ConnectDapp/ApproveConnection.js b/app/components/ConnectDapp/ApproveConnection.js
deleted file mode 100644
index 8554805b8..000000000
--- a/app/components/ConnectDapp/ApproveConnection.js
+++ /dev/null
@@ -1,202 +0,0 @@
-// @flow
-import React from 'react'
-import { SessionTypes } from '@walletconnect/types'
-import { compose } from 'recompose'
-import { connect } from 'react-redux'
-
-import { useWalletConnect } from '../../context/WalletConnect/WalletConnectContext'
-import { DEFAULT_NAMESPACES, ROUTES, MODAL_TYPES } from '../../core/constants'
-import CloseButton from '../CloseButton'
-import FullHeightPanel from '../Panel/FullHeightPanel'
-import WallletConnect from '../../assets/icons/wallet_connect.svg'
-import styles from '../../containers/ConnectDapp/styles.scss'
-import Confirm from '../../assets/icons/confirm_connection.svg'
-import Deny from '../../assets/icons/deny_connection.svg'
-import { showModal } from '../../modules/modal'
-
-const ApproveConnection = ({
- proposal,
- resetState,
- history,
- showSuccessNotification,
- showErrorNotification,
- net,
- address,
- showNetworkSwitchModal,
-}: {
- proposal: SessionTypes.Proposal,
- resetState: () => any,
- history: any,
- showSuccessNotification: ({ message: string }) => any,
- showErrorNotification: ({ message: string }) => any,
- net: string,
- address: string,
- showNetworkSwitchModal: ({
- dAppName: string,
- proposedNetwork: string,
- approveSession: (network?: string) => void,
- rejectSession: () => void,
- }) => void,
-}) => {
- const walletConnectCtx = useWalletConnect()
- const {
- proposer: { metadata },
- requiredNamespaces,
- } = proposal.params
-
- const approveSession = network => {
- walletConnectCtx
- .approveSession(
- proposal,
- [
- {
- address,
- chain: `neo3:${
- network || net === 'Custom' ? 'private' : net.toLowerCase()
- }`,
- },
- ],
- DEFAULT_NAMESPACES,
- )
- .catch(e => {
- // TODO: parse into a more user friendly error
- showErrorNotification({
- message: `An error occurred attempting to approve session: ${e}`,
- })
- })
-
- showSuccessNotification({
- message: `You have accepted connection from ${
- proposal ? metadata.name : 'unknown dApp'
- }.`,
- })
- history.push(ROUTES.DASHBOARD)
- }
-
- const rejectSession = () => {
- walletConnectCtx.rejectSession(proposal)
- showSuccessNotification({
- message: `You have rejected connection from ${
- proposal ? metadata.name : 'unknown dApp'
- }.`,
- })
- resetState()
- history.push(ROUTES.DASHBOARD)
- }
-
- const handleApproveSessionClick = () => {
- // 'neo3:testnet' or 'neo3:mainnet'
- const proposedNetwork = proposal.params.requiredNamespaces.neo3.chains[0]
-
- if (net === 'Custom' && proposedNetwork === 'neo3:private') {
- return approveSession()
- }
-
- const currentNetwork = `neo3:${
- net === 'Custom' ? 'private' : net.toLowerCase()
- }`
-
- if (
- proposedNetwork !== currentNetwork &&
- proposedNetwork !== 'neo3:private'
- ) {
- return showNetworkSwitchModal({
- dAppName: metadata.name,
- approveSession,
- rejectSession,
- proposedNetwork: proposal.params.requiredNamespaces.neo3.chains[0],
- })
- }
-
- if (
- proposedNetwork === 'neo3:private' &&
- proposedNetwork !== currentNetwork
- ) {
- return showErrorNotification({
- message: `${metadata.name ||
- 'unknown dApp'} is attempting to connect to a private network but you are currently on ${net}.`,
- })
- }
-
- approveSession()
- }
-
- return (
- {metadata.name} wants to connect
- {metadata.name} wants to connect
+
- {typeof error === 'string' - ? error - : 'An unknown error occurred please try again.'} -
-- All transactions requested by a connected Dapp will be presented for - signing before being broadcast to the blockchain. No action from the Dapp - will happen without your direct approval. -
- ) - - return ( -+ All transactions requested by a connected Dapp will be presented for + signing before being broadcast to the blockchain. No action from the Dapp + will happen without your direct approval. +
+ ) + + return ( +- Once your transaction has been confirmed it will appear in your - activity feed. -
-
-
-
- {walletConnectCtx.txHash}
-
+ Once your transaction has been confirmed it will appear in your + activity feed. +
+
+
+
+ {transactionHash}
+
{errorMessage}
+- {' '} - {dAppName} has made a session request for {requestedNetwork} however + {dAppName} has made a session request for {proposalNetwork} however you are currently on {net}, would you like to change networks and accept this request?
diff --git a/app/components/Modals/NetworkSwitchModal/index.js b/app/components/Modals/NetworkSwitchModal/index.js index bc4710003..678b4ed40 100644 --- a/app/components/Modals/NetworkSwitchModal/index.js +++ b/app/components/Modals/NetworkSwitchModal/index.js @@ -1,54 +1,24 @@ // @flow import { compose } from 'recompose' -import { injectIntl } from 'react-intl' -import { bindActionCreators } from 'redux' -import { connect } from 'react-redux' import { withActions, type Actions } from 'spunky' -import Modal from './NetworkSwitchModal' +import NetworkSwitchModal from './NetworkSwitchModal' import withNetworkData from '../../../hocs/withNetworkData' import withAuthData from '../../../hocs/withAuthData' import networkActions from '../../../actions/networkActions' -import { - showErrorNotification, - showSuccessNotification, - showInfoNotification, - hideNotification, -} from '../../../modules/notifications' -import accountActions from '../../../actions/accountActions' - -const actionCreators = { - showErrorNotification, - showSuccessNotification, - showInfoNotification, - hideNotification, -} +import nodeStorageActions from '../../../actions/nodeStorageActions' const mapActionsToProps = (actions: Actions): Object => ({ switchNetworks: networkId => actions.call({ networkId }), }) -const mapAccountActionsToProps = (actions, props) => ({ - loadWalletData: (net: string) => - actions.call({ - net, - address: props.address, - tokens: props.tokens, - chain: props.chain, - }), +const mapSaveNodeActionsToProps = actions => ({ + saveSelectedNode: ({ url, net, label }) => actions.call({ url, net, label }), }) -const mapDispatchToProps = dispatch => - bindActionCreators(actionCreators, dispatch) - export default compose( - connect( - null, - mapDispatchToProps, - ), - injectIntl, withNetworkData(), withAuthData(), withActions(networkActions, mapActionsToProps), - withActions(accountActions, mapAccountActionsToProps), -)(Modal) + withActions(nodeStorageActions, mapSaveNodeActionsToProps), +)(NetworkSwitchModal) diff --git a/app/components/Modals/TransferNftModal/TransferNftModal.jsx b/app/components/Modals/TransferNftModal/TransferNftModal.jsx index bbc8116b3..ec5717c03 100644 --- a/app/components/Modals/TransferNftModal/TransferNftModal.jsx +++ b/app/components/Modals/TransferNftModal/TransferNftModal.jsx @@ -1,9 +1,10 @@ // @flow import React, { useState, useEffect } from 'react' import { FormattedMessage } from 'react-intl' -import { wallet as n3Wallet } from '@cityofzion/neon-js-next' +import { wallet as n3Wallet } from '@cityofzion/neon-js' import { BSNeo3 } from '@cityofzion/bs-neo3' +import { NeonInvoker } from '@cityofzion/neon-invoker' import { NFT } from '../../../containers/NftGallery/NftGallery' import Button from '../../Button' import SelectInput from '../../Inputs/SelectInput' @@ -12,8 +13,6 @@ import N3Fees from '../../Send/N3Fees' import BaseModal from '../BaseModal' import styles from './TransferNftModal.scss' import { getNode, getRPCEndpoint } from '../../../actions/nodeStorageActions' -import N3Helper from '../../../context/WalletConnect/helpers' -import { convertToArbitraryDecimals } from '../../../core/formatters' import { addPendingTransaction } from '../../../actions/pendingTransactionActions' import { useContactsContext } from '../../../context/contacts/ContactsContext' import { MODAL_TYPES } from '../../../core/constants' @@ -31,10 +30,10 @@ type Props = { address: string, tokenId: string, wif: string, - showSuccessNotification: ({ message: string }) => any, - showErrorNotification: ({ message: string }) => any, - showInfoNotification: ({ message: string }) => any, - hideNotification: (id: string) => void, + showSuccessNotification({ message: string }): any, + showErrorNotification({ message: string }): any, + showInfoNotification({ message: string, autoDismiss: number }): any, + hideNotification(id: string): any, dispatch: any => any, isHardwareLogin: boolean, signingFunction: () => void, @@ -52,14 +51,14 @@ export default function TransferNftModal(props: Props) { address, wif, dispatch, - isHardwareLogin, - signingFunction, showSuccessNotification, showErrorNotification, showInfoNotification, hideNotification, recipientAddressProp, publicKey, + isHardwareLogin, + signingFunction, } = props function handleSubmit() {} @@ -72,8 +71,7 @@ export default function TransferNftModal(props: Props) { recipientAddressProp ?? '', ) const [recipientAddressError, setRecipientAddressError] = useState('') - const [gasFee, setGasFee] = useState(DEFAULT_FEES) - const [feesInitialized, setFeesInitialized] = useState(false) + const [fees, setFees] = useState(DEFAULT_FEES) const [sendButtonDisabled, setSendButtonDisabled] = useState(false) const [loading, setLoading] = useState(true) const { contacts } = useContactsContext() @@ -160,53 +158,54 @@ export default function TransferNftModal(props: Props) { async function transfer() { try { setLoading(true) - let endpoint = await getNode(net) - if (!endpoint) { - endpoint = await getRPCEndpoint(net) + let rpcAddress = await getNode(net) + if (!rpcAddress) { + rpcAddress = await getRPCEndpoint(net) } const account = new n3Wallet.Account(isHardwareLogin ? publicKey : wif) - const testReq = { - params: { - request: { - method: 'multiInvoke', - params: { - invocations: [ - { - scriptHash: contract, - operation: 'transfer', - args: [ - { - type: 'Hash160', - value: recipientAddress, - }, - { type: 'ByteArray', value: tokenId }, - { type: 'Any', value: null }, - ], - }, - ], - signers: [{ scopes: 1 }], - }, - }, - }, - } - const results = await new N3Helper(endpoint, 0).rpcCall( + const invoker = await NeonInvoker.init({ + rpcAddress, account, - testReq, - isHardwareLogin, - signingFunction, - showInfoNotification, - hideNotification, - ) + signingCallback: signingFunction, + }) + + let notificationId + + if (isHardwareLogin) { + notificationId = showInfoNotification({ + message: 'Please sign the transaction on your hardware device', + autoDismiss: 0, + }) + } + + const hash = await invoker.invokeFunction({ + invocations: [ + { + scriptHash: contract, + operation: 'transfer', + args: [ + { + type: 'Hash160', + value: recipientAddress, + }, + { type: 'ByteArray', value: tokenId }, + { type: 'Any', value: null }, + ], + }, + ], + }) - const { result } = results + if (notificationId) { + hideNotification(notificationId) + } dispatch( addPendingTransaction.call({ address, net, tx: { - hash: result, + hash, sendEntries: [ { amount: 1, address, contractHash: contract, symbol: 'N/A' }, ], @@ -217,67 +216,52 @@ export default function TransferNftModal(props: Props) { showSuccessNotification({ message: 'Transaction pending! Your NFT will be transferred shortly.', }) - setLoading(false) - hideModal() } catch (e) { - hideModal() showErrorNotification({ message: e.message, }) + } finally { setLoading(false) + hideModal() } } - useEffect(() => { - async function testInvoke() { - setLoading(true) - let endpoint = await getNode(net) - if (!endpoint) { - endpoint = await getRPCEndpoint(net) - } - const account = new n3Wallet.Account(address) - const testReq = { - params: { - request: { - method: 'testInvoke', - params: { - invocations: [ + useEffect( + () => { + ;(async () => { + let rpcAddress = await getNode(net) + if (!rpcAddress) { + rpcAddress = await getRPCEndpoint(net) + } + const account = new n3Wallet.Account(isHardwareLogin ? publicKey : wif) + + const invoker = await NeonInvoker.init({ rpcAddress, account }) + const { networkFee, systemFee } = await invoker.calculateFee({ + invocations: [ + { + scriptHash: contract, + operation: 'transfer', + args: [ { - scriptHash: contract, - operation: 'transfer', - args: [ - { - type: 'Hash160', - value: address, - }, - { type: 'ByteArray', value: tokenId }, - { type: 'Any', value: null }, - ], + type: 'Hash160', + value: address, }, + { type: 'ByteArray', value: tokenId }, + { type: 'Any', value: null }, ], - signers: [{ scopes: 1 }], }, - }, - }, - } - const results = await new N3Helper(endpoint, 0).rpcCall( - account, - testReq, - isHardwareLogin, - signingFunction, - showInfoNotification, - hideNotification, - ) - const fee = convertToArbitraryDecimals(results.result.gasconsumed) - setGasFee({ - networkFee: fee, - systemFee: 0, - }) - setFeesInitialized(true) - setLoading(false) - } - testInvoke() - }, []) + ], + signers: [{ scopes: 1 }], + }) + + setFees({ + networkFee, + systemFee, + }) + })() + }, + [address, tokenId, isHardwareLogin, publicKey, wif, net, contract], + ) function createContactList(): Array