@@ -460,7 +460,7 @@ const confluxFaucetContract = new Conflux().Contract({
460460
461461// 初始化钱包
462462window . conflux = new window . AnyWeb . Provider ( {
463- appId : 'ccb32218-56d4-4765-ba97-867adad7a63c ' ,
463+ appId : '693b6401-135a-4dc3-846b-1c05ad2572f6 ' ,
464464} ) //
465465const provider = window . conflux
466466
@@ -485,20 +485,20 @@ async function walletInitialized() {
485485 const transferFromAccountInput = getElement ( 'from-account' )
486486 const transferToAccountInput = getElement ( 'to-account' )
487487
488- const addNetworkButton = getElement ( 'add_network' )
489- const switchNetworkButton = getElement ( 'switch_network' )
490488 const deployContract = getElement ( 'deploy_contract' )
491489
492490 function authed ( address ) {
491+ if ( ! address || address === '' ) {
492+ return unAuthed ( )
493+ }
493494 getElement ( 'address' ) . innerHTML = address
494495 console . log ( 'authed address: ' , address )
495496 sendNativeTokenButton . disabled = false
496497 approveButton . disabled = false
497498 transferFromButton . disabled = false
498- addNetworkButton . disabled = false
499- switchNetworkButton . disabled = false
500499 deployContract . disabled = false
501500 getCFXButton . disabled = false
501+ connectButton . disabled = true
502502 }
503503
504504 function unAuthed ( ) {
@@ -508,14 +508,15 @@ async function walletInitialized() {
508508 approveButton . disabled = true
509509 transferFromButton . disabled = true
510510 getCFXButton . disabled = true
511- addNetworkButton . disabled = true
512- switchNetworkButton . disabled = true
513511 deployContract . disabled = true
512+ connectButton . disabled = false
514513 }
515514
516515 provider . on ( 'accountsChanged' , ( accounts ) => {
517516 console . log ( 'accountsChanged, accounts = ' , accounts )
518- if ( ! accounts . length ) return unAuthed ( )
517+ if ( ! accounts || ! accounts . length || accounts . length === 0 ) {
518+ return unAuthed ( )
519+ }
519520 authed ( accounts [ 0 ] )
520521 } )
521522
@@ -545,7 +546,11 @@ async function walletInitialized() {
545546 getElement ( 'chainId' ) . innerHTML = chainId
546547 getElement ( 'networkId' ) . innerHTML = networkId
547548
548- if ( ! alreadyAuthedAddresses . length ) {
549+ if (
550+ ! alreadyAuthedAddresses ||
551+ ! alreadyAuthedAddresses . length ||
552+ alreadyAuthedAddresses . length === 0
553+ ) {
549554 unAuthed ( )
550555 } else {
551556 authed ( alreadyAuthedAddresses [ 0 ] )
@@ -557,7 +562,7 @@ async function walletInitialized() {
557562 method : 'cfx_requestAccounts' ,
558563 } )
559564 . then ( authed )
560- . catch ( ( error ) => console . error ( 'error' , error . message || error ) )
565+ . catch ( console . error )
561566 }
562567
563568 // send native token to the connected address
@@ -592,6 +597,7 @@ async function walletInitialized() {
592597 provider
593598 . request ( { method : 'cfx_sendTransaction' , params : [ tx ] } )
594599 . then ( ( result ) => {
600+ getElement ( 'get_cfx_result' ) . innerHTML = result
595601 console . log ( 'result' , result )
596602 } )
597603 } catch ( err ) {
@@ -647,47 +653,6 @@ async function walletInitialized() {
647653 }
648654 }
649655
650- // request to add network
651- addNetworkButton . onclick = ( ) => {
652- provider
653- . request ( {
654- method : 'wallet_addConfluxChain' ,
655- params : [
656- {
657- chainId : '0x406' ,
658- chainName : 'EVM Conflux' ,
659- nativeCurrency : {
660- name : 'Conflux' ,
661- symbol : 'CFX' ,
662- decimals : 18 ,
663- } ,
664- rpcUrls : [ 'http://47.104.89.179:12537' ] ,
665- blockExplorerUrls : [ 'https://confluxscan.io' ] ,
666- } ,
667- ] ,
668- } )
669- . then ( console . log )
670- . catch ( console . log )
671- }
672-
673- // request to switch network
674- switchNetworkButton . onclick = ( ) => {
675- provider
676- . request ( {
677- method : 'wallet_switchConfluxChain' ,
678- params : [ { chainId : '0x1' } ] ,
679- } )
680- . then ( ( ) => {
681- provider
682- . request ( { method : 'cfx_chainId' } )
683- . then ( ( idResult ) => ( getElement ( 'chainId' ) . innerHTML = idResult ) )
684- provider
685- . request ( { method : 'cfx_netVersion' } )
686- . then ( ( netResult ) => ( getElement ( 'networkId' ) . innerHTML = netResult ) )
687- } )
688- . catch ( console . log )
689- }
690-
691656 deployContract . onclick = async ( ) => {
692657 try {
693658 const [ connectedAddress ] = await provider . request ( {
@@ -701,7 +666,7 @@ async function walletInitialized() {
701666 provider
702667 . request ( { method : 'cfx_sendTransaction' , params : [ tx ] } )
703668 . then ( ( result ) => {
704- getElement ( 'get_cfx_result ' ) . innerHTML = result
669+ getElement ( 'deploy_contract_result ' ) . innerHTML = result
705670 console . log ( 'result' , result )
706671 } )
707672 } catch ( err ) {
0 commit comments