4
4
/* eslint-disable react/prop-types */
5
5
import React , { PureComponent } from 'react' ;
6
6
import type { Element } from 'react' ;
7
- import url from 'url' ;
8
- import querystring from 'querystring' ;
9
7
import fs from 'fs' ;
10
8
import dateformat from 'dateformat' ;
11
9
import Modal from 'react-modal' ;
@@ -20,6 +18,7 @@ import routes from '../constants/routes.json';
20
18
import Logo from '../assets/img/logobig.png' ;
21
19
import { Info , Transaction } from './AppState' ;
22
20
import Utils from '../utils/utils' ;
21
+ import { parseZcashURI , ZcashURITarget } from '../utils/uris' ;
23
22
24
23
const ExportPrivKeyModal = ( { modalIsOpen, exportedPrivKeys, closeModal } ) => {
25
24
return (
@@ -184,7 +183,7 @@ type Props = {
184
183
info : Info ,
185
184
addresses : string [ ] ,
186
185
transactions : Transaction [ ] ,
187
- setSendTo : ( address : string , amount : number | null , memo : string | null ) => void ,
186
+ setSendTo : ( targets : ZcashURITarget [ ] | ZcashURITarget ) => void ,
188
187
getPrivKeyAsString : ( address : string ) => string ,
189
188
importPrivKeys : ( keys : string [ ] ) => void ,
190
189
history : PropTypes . object . isRequired ,
@@ -226,7 +225,7 @@ class Sidebar extends PureComponent<Props, State> {
226
225
openErrorModal (
227
226
'Zecwallet Fullnode' ,
228
227
< div className = { cstyles . verticalflex } >
229
- < div className = { cstyles . margintoplarge } > Zecwallet Fullnode v0.9.18 </ div >
228
+ < div className = { cstyles . margintoplarge } > Zecwallet Fullnode v0.9.19 </ div >
230
229
< div className = { cstyles . margintoplarge } > Built with Electron. Copyright (c) 2018-2020, Aditya Kulkarni.</ div >
231
230
< div className = { cstyles . margintoplarge } >
232
231
The MIT License (MIT) Copyright (c) 2018-present Zecwallet
@@ -256,9 +255,11 @@ class Sidebar extends PureComponent<Props, State> {
256
255
// Donate button
257
256
ipcRenderer . on ( 'donate' , ( ) => {
258
257
setSendTo (
259
- Utils . getDonationAddress ( testnet ) ,
260
- Utils . getDefaultDonationAmount ( testnet ) ,
261
- Utils . getDefaultDonationMemo ( testnet )
258
+ new ZcashURITarget (
259
+ Utils . getDonationAddress ( testnet ) ,
260
+ Utils . getDefaultDonationAmount ( testnet ) ,
261
+ Utils . getDefaultDonationMemo ( testnet )
262
+ )
262
263
) ;
263
264
264
265
history . push ( routes . SEND ) ;
@@ -418,41 +419,27 @@ class Sidebar extends PureComponent<Props, State> {
418
419
const { openErrorModal, setSendTo, history } = this . props ;
419
420
420
421
const errTitle = 'URI Error' ;
421
- const errBody = (
422
- < span >
423
- The URI "{ escape ( uri ) } " was not recognized.
424
- < br />
425
- Please type in a valid URI of the form " zcash:address?amout=xx& memo = yy & quot ;
426
- </ span >
427
- ) ;
422
+ const getErrorBody = ( explain : string ) : Element < 'div' > => {
423
+ return (
424
+ < div >
425
+ < span > { explain } </ span >
426
+ < br />
427
+ </ div >
428
+ ) ;
429
+ } ;
428
430
429
431
if ( ! uri || uri === '' ) {
430
- openErrorModal ( errTitle , errBody ) ;
432
+ openErrorModal ( errTitle , getErrorBody ( 'URI was not found or invalid' ) ) ;
431
433
return ;
432
434
}
433
435
434
- const parsedUri = url . parse ( uri ) ;
435
- if ( ! parsedUri || parsedUri . protocol !== 'zcash:' || ! parsedUri . query ) {
436
- openErrorModal ( errTitle , errBody ) ;
436
+ const parsedUri = parseZcashURI ( uri ) ;
437
+ if ( typeof parsedUri === 'string' ) {
438
+ openErrorModal ( errTitle , getErrorBody ( parsedUri ) ) ;
437
439
return ;
438
440
}
439
441
440
- const address = parsedUri . host ;
441
- if ( ! address || ! ( Utils . isTransparent ( address ) || Utils . isZaddr ( address ) ) ) {
442
- openErrorModal ( errTitle , < span > The address ${ address } was not recognized as a Zcash address</ span > ) ;
443
- return ;
444
- }
445
-
446
- const parsedParams = querystring . parse ( parsedUri . query ) ;
447
- if ( ! parsedParams || ( ! parsedParams . amt && ! parsedParams . amount ) ) {
448
- openErrorModal ( errTitle , errBody ) ;
449
- return ;
450
- }
451
-
452
- const amount = parsedParams . amt || parsedParams . amount ;
453
- const memo = parsedParams . memo || '' ;
454
-
455
- setSendTo ( address , amount , memo ) ;
442
+ setSendTo ( parsedUri ) ;
456
443
history . push ( routes . SEND ) ;
457
444
} ;
458
445
0 commit comments