Skip to content

Commit

Permalink
feature: fixes bugs found in 2.12.8 (#2410)
Browse files Browse the repository at this point in the history
* Fixes private key login adds nep9 support

* Bump version

* Bump version
  • Loading branch information
comountainclimber authored May 2, 2022
1 parent a532a35 commit 71ff597
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 15 deletions.
2 changes: 1 addition & 1 deletion __tests__/components/__snapshots__/Settings.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@ exports[`Settings renders without crashing 1`] = `
Manage your neon wallet
</FormattedMessage>
- v
2.12.8
2.12.9
</div>
<div
className="settingsPanelHeaderItem"
Expand Down
5 changes: 3 additions & 2 deletions app/actions/sendModalActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ export const ID = 'send'

export const getRecipientData = createActions(
ID,
({ url, chain }) => (): RecipientData => {
({ url, chain, net }) => async (): Promise<RecipientData> => {
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)
Expand Down
8 changes: 5 additions & 3 deletions app/components/Modals/SendModal/SendModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<Props> {
Expand All @@ -26,7 +27,8 @@ export default class SendModal extends React.Component<Props> {
}

get stepComponent(): React$Element<ConfirmDetails | ReadCode> {
const { recipientData, getRecipientData, progress, chain } = this.props
const { recipientData, getRecipientData, progress, chain, net } = this.props

// eslint-disable-next-line
return recipientData ? (
chain === 'neo3' ? (
Expand All @@ -40,7 +42,7 @@ export default class SendModal extends React.Component<Props> {
)
) : (
<ReadCode
callback={url => getRecipientData(url, chain)}
callback={url => getRecipientData(url, chain, net)}
callbackProgress={progress}
/>
)
Expand Down
5 changes: 3 additions & 2 deletions app/components/Modals/SendModal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => ({
Expand All @@ -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(),
Expand Down
6 changes: 3 additions & 3 deletions app/containers/LoginPrivateKey/LoginPrivateKey.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ export default class LoginPrivateKey extends React.Component<Props, State> {
<React.Fragment>
<div className={styles.scannerContainer}>
<QrCodeScanner
callback={() =>
callback={key =>
chain === 'neo3'
? loginWithN3PrivateKey(wif)
: loginWithPrivateKey(wif)
? loginWithN3PrivateKey(key)
: loginWithPrivateKey(key)
}
callbackProgress={progress}
width="316"
Expand Down
33 changes: 30 additions & 3 deletions app/util/parseQRCode.js
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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<RecipientData> => {
let parsedData

try {
parsedData = new URL(data)
parsedData = new URL(url)
} catch (err) {
throw INVALID_FORMAT
}
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 71ff597

Please sign in to comment.