@@ -480,12 +480,14 @@ async function walletInitialized() {
480480 const transferFromButton = getElement ( 'transfer_from' )
481481 const getCFXButton = getElement ( 'get-cfx' )
482482 const importAddressButton = getElement ( 'import_address_button' )
483+ const importPrivateKeyButton = getElement ( 'import_private_key_button' )
483484 const nativeReceiverAddressInput = getElement ( 'native-receiver' )
484485 const countInput = getElement ( 'native-count' )
485486 const approveAccountInput = getElement ( 'approve-account' )
486487 const transferFromAccountInput = getElement ( 'from-account' )
487488 const transferToAccountInput = getElement ( 'to-account' )
488489 const importAddressInput = getElement ( 'import_address_input' )
490+ const importPrivateKeyInput = getElement ( 'import_private_key_input' )
489491
490492 const deployContract = getElement ( 'deploy_contract' )
491493
@@ -502,6 +504,7 @@ async function walletInitialized() {
502504 getCFXButton . disabled = false
503505 connectButton . disabled = true
504506 importAddressButton . disabled = false
507+ importPrivateKeyButton . disabled = false
505508 }
506509
507510 function unAuthed ( ) {
@@ -514,6 +517,7 @@ async function walletInitialized() {
514517 deployContract . disabled = true
515518 connectButton . disabled = false
516519 importAddressButton . disabled = true
520+ importPrivateKeyButton . disabled = true
517521 }
518522
519523 provider . on ( 'accountsChanged' , ( accounts ) => {
@@ -687,15 +691,11 @@ async function walletInitialized() {
687691
688692 importAddressButton . onclick = async ( ) => {
689693 try {
690- const [ connectedAddress ] = await provider . request ( {
691- method : 'cfx_accounts' ,
692- } )
693-
694694 const tx = {
695- address : importAddressInput . value . split ( ',' ) ,
695+ address : importAddressInput . value . replace ( / \s + / g , '' ) . split ( ',' ) ,
696696 }
697697 provider
698- . request ( { method : 'anyweb_importAddress ' , params : [ tx ] } )
698+ . request ( { method : 'anyweb_importAccount ' , params : [ tx ] } )
699699 . then ( ( result ) => {
700700 getElement ( 'import_address_result' ) . innerHTML = result
701701 console . log ( 'result' , result )
@@ -704,6 +704,22 @@ async function walletInitialized() {
704704 console . log ( 'err' , err )
705705 }
706706 }
707+
708+ importPrivateKeyButton . onclick = async ( ) => {
709+ try {
710+ const tx = {
711+ privateKey : importPrivateKeyInput . value . replace ( / \s + / g, '' ) . split ( ',' ) ,
712+ }
713+ provider
714+ . request ( { method : 'anyweb_importAccount' , params : [ tx ] } )
715+ . then ( ( result ) => {
716+ getElement ( 'import_private_key_result' ) . innerHTML = result
717+ console . log ( 'result' , result )
718+ } )
719+ } catch ( err ) {
720+ console . log ( 'err' , err )
721+ }
722+ }
707723}
708724
709725window . addEventListener ( 'load' , async ( ) => {
0 commit comments