@@ -562,7 +562,6 @@ async function walletInitialized() {
562562 // connect
563563 const connectButton = getElement ( 'connect' )
564564 const DeauthorizeButton = getElement ( 'Deauthorize' )
565- const logoutButton = getElement ( 'Logout' )
566565 const sendNativeTokenButton = getElement ( 'send_native_token' )
567566 const approveButton = getElement ( 'approve' )
568567 const transferFromButton = getElement ( 'transfer_from' )
@@ -576,7 +575,6 @@ async function walletInitialized() {
576575 const transferToAccountInput = getElement ( 'to-account' )
577576 const importAddressInput = getElement ( 'import_address_input' )
578577 const importAddressNameInput = getElement ( 'import_address_name_input' )
579- const identifyButton = getElement ( 'identify_button' )
580578
581579 const deployContract = getElement ( 'deploy_contract' )
582580
@@ -597,9 +595,7 @@ async function walletInitialized() {
597595 gatewayTestButton . disabled = false
598596 connectButton . disabled = true
599597 DeauthorizeButton . disabled = false
600- logoutButton . disabled = false
601598 importAddressButton . disabled = false
602- identifyButton . disabled = false
603599 }
604600
605601 function unAuthed ( ) {
@@ -614,9 +610,7 @@ async function walletInitialized() {
614610 deployContract . disabled = true
615611 connectButton . disabled = false
616612 DeauthorizeButton . disabled = true
617- logoutButton . disabled = true
618613 importAddressButton . disabled = true
619- identifyButton . disabled = true
620614 }
621615
622616 provider . on ( 'accountsChanged' , ( accounts ) => {
@@ -636,37 +630,38 @@ async function walletInitialized() {
636630 provider . request ( { method : 'anyweb_version' } ) . then ( ( version ) => {
637631 getElement ( 'version' ) . innerHTML = version
638632 } )
639- // const data = await provider.request({
640- // method: 'cfx_accounts',
641- // params: [
642- // {
643- // availableNetwork: [1, 1029],
644- // scopes: ['baseInfo', 'identity'],
645- // },
646- // ],
647- // })
648- // const { chainId, networkId, address: alreadyAuthedAddresses, code } = data
649- // console.log(
650- // 'DApp 获取到的授权结果',
651- // chainId,
652- // networkId,
653- // alreadyAuthedAddresses,
654- // code
655- // )
656- // setState(data)
657- // getElement('initialized').innerHTML = 'initialized'
658- // getElement('chainId').innerHTML = chainId
659- // getElement('networkId').innerHTML = networkId
660- //
661- // if (
662- // !alreadyAuthedAddresses ||
663- // !alreadyAuthedAddresses.length ||
664- // alreadyAuthedAddresses.length === 0
665- // ) {
666- // unAuthed()
667- // } else {
668- // authed(alreadyAuthedAddresses[0], code)
669- // }
633+
634+ const data = await provider . request ( {
635+ method : 'cfx_accounts' ,
636+ params : [
637+ {
638+ availableNetwork : [ 1 , 1029 ] ,
639+ scopes : [ 'baseInfo' , 'identity' ] ,
640+ } ,
641+ ] ,
642+ } )
643+ const { chainId, networkId, address : alreadyAuthedAddresses , code } = data
644+ console . log (
645+ 'DApp 获取到的授权结果' ,
646+ chainId ,
647+ networkId ,
648+ alreadyAuthedAddresses ,
649+ code
650+ )
651+ setState ( data )
652+ getElement ( 'initialized' ) . innerHTML = 'initialized'
653+ getElement ( 'chainId' ) . innerHTML = chainId
654+ getElement ( 'networkId' ) . innerHTML = networkId
655+
656+ if (
657+ ! alreadyAuthedAddresses ||
658+ ! alreadyAuthedAddresses . length ||
659+ alreadyAuthedAddresses . length === 0
660+ ) {
661+ unAuthed ( )
662+ } else {
663+ authed ( alreadyAuthedAddresses [ 0 ] , code )
664+ }
670665 } catch ( e ) {
671666 unAuthed ( )
672667 console . error ( 'try 到错误了' , e )
@@ -714,14 +709,6 @@ async function walletInitialized() {
714709 . then ( unAuthed )
715710 . catch ( console . error )
716711 }
717- logoutButton . onclick = ( ) => {
718- provider
719- . request ( {
720- method : 'anyweb_logout' ,
721- } )
722- . then ( unAuthed )
723- . catch ( console . error )
724- }
725712
726713 // send native token to the connected address
727714 sendNativeTokenButton . onclick = async ( ) => {
@@ -900,19 +887,6 @@ async function walletInitialized() {
900887 console . log ( 'err' , err )
901888 }
902889 }
903-
904- identifyButton . onclick = async ( ) => {
905- try {
906- provider
907- . request ( { method : 'anyweb_identify' , params : [ ] } )
908- . then ( ( result ) => {
909- getElement ( 'identify_result' ) . innerHTML = result
910- console . log ( 'result' , result )
911- } )
912- } catch ( err ) {
913- console . log ( 'err' , err )
914- }
915- }
916890}
917891
918892window . addEventListener ( 'load' , async ( ) => {
0 commit comments