diff --git a/__tests__/components/__snapshots__/Settings.test.js.snap b/__tests__/components/__snapshots__/Settings.test.js.snap index 0e73f14d9..c40b8b6cc 100644 --- a/__tests__/components/__snapshots__/Settings.test.js.snap +++ b/__tests__/components/__snapshots__/Settings.test.js.snap @@ -953,7 +953,7 @@ exports[`Settings renders without crashing 1`] = ` Manage your neon wallet - v - 2.12.8 + 2.12.9
(): RecipientData => { + ({ url, chain, net }) => async (): Promise => { try { - if (chain === 'neo2') return parseQRCode(url) + if (chain === 'neo2' || url.includes('neo:')) + return parseQRCode({ url, net, chain }) return { address: url, amount: '', asset: '', reference: '' } } catch (msg) { throw new Error(msg) diff --git a/app/components/Modals/SendModal/SendModal.jsx b/app/components/Modals/SendModal/SendModal.jsx index f05a2fc12..5788d0411 100644 --- a/app/components/Modals/SendModal/SendModal.jsx +++ b/app/components/Modals/SendModal/SendModal.jsx @@ -10,11 +10,12 @@ import type { RecipientData } from '../../../util/parseQRCode' type Props = { hideModal: () => any, pushQRCodeData: (data: Object) => any, - getRecipientData: (url: string, chain?: string) => any, + getRecipientData: (url: string, chain?: string, net: string) => any, clearRecipientData: () => null, recipientData: ?RecipientData, progress: ProgressState, chain: string, + net: string, } export default class SendModal extends React.Component { @@ -26,7 +27,8 @@ export default class SendModal extends React.Component { } get stepComponent(): React$Element { - const { recipientData, getRecipientData, progress, chain } = this.props + const { recipientData, getRecipientData, progress, chain, net } = this.props + // eslint-disable-next-line return recipientData ? ( chain === 'neo3' ? ( @@ -40,7 +42,7 @@ export default class SendModal extends React.Component { ) ) : ( getRecipientData(url, chain)} + callback={url => getRecipientData(url, chain, net)} callbackProgress={progress} /> ) diff --git a/app/components/Modals/SendModal/index.js b/app/components/Modals/SendModal/index.js index 0a2b94e22..877d1d7db 100644 --- a/app/components/Modals/SendModal/index.js +++ b/app/components/Modals/SendModal/index.js @@ -8,9 +8,10 @@ import { } from '../../../actions/sendModalActions' import withFailureNotification from '../../../hocs/withFailureNotification' import withChainData from '../../../hocs/withChainData' +import withNetworkData from '../../../hocs/withNetworkData' const mapGetDataToProps = action => ({ - getRecipientData: (url, chain) => action.call({ url, chain }), + getRecipientData: (url, chain, net) => action.call({ url, chain, net }), }) const mapClearDataToProps = action => ({ @@ -28,7 +29,7 @@ export default compose( `An error occurred while scanning this QR code: ${message}. Please try again.`, ), withProgress(getRecipientData), - + withNetworkData(), withActions(clearRecipientData, mapClearDataToProps), withData(clearRecipientData, mapRecipientDataToProps), withChainData(), diff --git a/app/containers/LoginPrivateKey/LoginPrivateKey.jsx b/app/containers/LoginPrivateKey/LoginPrivateKey.jsx index 39eb49e8f..b6e262199 100644 --- a/app/containers/LoginPrivateKey/LoginPrivateKey.jsx +++ b/app/containers/LoginPrivateKey/LoginPrivateKey.jsx @@ -58,10 +58,10 @@ export default class LoginPrivateKey extends React.Component {
+ callback={key => chain === 'neo3' - ? loginWithN3PrivateKey(wif) - : loginWithPrivateKey(wif) + ? loginWithN3PrivateKey(key) + : loginWithPrivateKey(key) } callbackProgress={progress} width="316" diff --git a/app/util/parseQRCode.js b/app/util/parseQRCode.js index 6521f0f42..24f754baf 100644 --- a/app/util/parseQRCode.js +++ b/app/util/parseQRCode.js @@ -1,5 +1,9 @@ // @flow +import { rpc as n3Rpc } from '@cityofzion/neon-js-next' +import { api, u, rpc, sc, wallet } from '@cityofzion/neon-js' + import hashToSymbol from './hashToSymbol' +import { getNode, getRPCEndpoint } from '../actions/nodeStorageActions' const INVALID_FORMAT = 'Invalid format' const INVALID_PROTOCOL = 'Invalid protocol' @@ -13,11 +17,19 @@ export type RecipientData = { reference: ?string, } -const parseQRCode = (data: string): RecipientData => { +const parseQRCode = async ({ + url, + net, + chain, +}: { + url: string, + net: string, + chain: string, +}): Promise => { let parsedData try { - parsedData = new URL(data) + parsedData = new URL(url) } catch (err) { throw INVALID_FORMAT } @@ -30,9 +42,24 @@ const parseQRCode = (data: string): RecipientData => { let asset = searchParams.get('asset') const assetIsHash = asset && asset !== 'NEO' && asset !== 'GAS' - if (assetIsHash) { + if (assetIsHash && chain === 'neo2') { asset = hashToSymbol(asset) if (!asset) throw UNRECOGNIZED_ASSET + } else { + let endpoint = await getNode(net) + if (!endpoint) { + endpoint = await getRPCEndpoint(net) + } + const tokenNameResponse = await new n3Rpc.RPCClient(endpoint) + .invokeFunction(asset, 'symbol') + .catch(e => { + console.error({ e }) + }) + const symbol = atob(tokenNameResponse.stack[0].value) + if (symbol) asset = symbol + else { + throw UNRECOGNIZED_ASSET + } } return { diff --git a/package.json b/package.json index f622a38c4..5f010bc20 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "Neon", - "version": "2.12.8", + "version": "2.12.9", "main": "./main.js", "description": "Light wallet for NEO blockchain", "homepage": "https://github.com/CityOfZion/neon-wallet",