@@ -584,10 +584,27 @@ const msgParams = {
584584// 初始化钱包
585585const provider = new window . AnyWeb . Provider ( {
586586 appId : '693b6401-135a-4dc3-846b-1c05ad2572f6' ,
587- } ) //
587+ } )
588588console . log ( '开始监听是否准备好' )
589589provider . on ( 'ready' , async ( ) => {
590- walletInitialized ( )
590+ await walletInitialized ( )
591+ window . addEventListener ( 'load' , async ( ) => {
592+ if ( ! isAnyWebInstall ( ) ) {
593+ return
594+ }
595+ getElement ( 'installed' ) . innerHTML = 'installed'
596+ if ( window . localStorage . getItem ( '__FLUENT_USE_MODERN_PROVIDER_API__' ) ) {
597+ getElement ( 'installed-section' ) . style . display = 'block'
598+ }
599+ if ( isAnyWebInstall ( ) ) {
600+ console . log ( 'DApp 已经检查到OK了' )
601+ provider . request ( { method : 'anyweb_version' } ) . then ( ( version ) => {
602+ getElement ( 'version' ) . innerHTML = version
603+ } )
604+ } else {
605+ alert ( '找不到AnyWeb SDK, 请检查是否正确配置' )
606+ }
607+ } )
591608} )
592609
593610function getElement ( id ) {
@@ -636,7 +653,6 @@ async function walletInitialized() {
636653 const connectButton = getElement ( 'connect' )
637654 const DeauthorizeButton = getElement ( 'Deauthorize' )
638655 const logoutButton = getElement ( 'Logout' )
639- const sendNativeTokenButton = getElement ( 'send_native_token' )
640656 const approveButton = getElement ( 'approve' )
641657 const transferFromButton = getElement ( 'transfer_from' )
642658 const getCFXButton = getElement ( 'get-cfx' )
@@ -664,7 +680,6 @@ async function walletInitialized() {
664680 getElement ( 'oauth_code' ) . innerHTML = oauthCode
665681 }
666682 console . log ( 'authed address: ' , address )
667- sendNativeTokenButton . disabled = false
668683 approveButton . disabled = false
669684 transferFromButton . disabled = false
670685 deployContract . disabled = false
@@ -682,7 +697,6 @@ async function walletInitialized() {
682697 getElement ( 'address' ) . innerHTML = 'N/A'
683698 getElement ( 'oauth_code' ) . innerHTML = 'N/A'
684699 console . log ( 'unauthed' )
685- sendNativeTokenButton . disabled = true
686700 approveButton . disabled = true
687701 transferFromButton . disabled = true
688702 getCFXButton . disabled = true
@@ -801,29 +815,6 @@ async function walletInitialized() {
801815 . catch ( console . error )
802816 }
803817
804- // send native token to the connected address
805- sendNativeTokenButton . onclick = async ( ) => {
806- const connectedAddress = address [ 0 ]
807- const payload = {
808- from : connectedAddress ,
809- value : Drip . fromCFX ( countInput . value ) ,
810- to : nativeReceiverAddressInput . value ,
811- }
812-
813- const gatewayPayload = {
814- test : 'test' ,
815- }
816-
817- provider
818- . request ( {
819- method : 'cfx_sendTransaction' ,
820- params : [ payload , gatewayPayload ] ,
821- } )
822- . then ( ( result ) => {
823- getElement ( 'send_native_token_result' ) . innerHTML = `txhash: ${ result } `
824- } )
825- . catch ( ( error ) => console . error ( 'error' , error . message || error ) )
826- }
827818 getCFXButton . onclick = async ( ) => {
828819 try {
829820 const connectedAddress = address [ 0 ]
@@ -969,8 +960,7 @@ async function walletInitialized() {
969960 provider
970961 . request ( { method : 'cfx_sendTransaction' , params : [ tx ] } )
971962 . then ( ( result ) => {
972- getElement ( 'deploy_contract_result' ) . innerHTML =
973- result . transactionHash
963+ getElement ( 'deploy_contract_result' ) . innerHTML = result
974964 console . log ( 'result' , result )
975965 } )
976966 } catch ( err ) {
@@ -1036,23 +1026,3 @@ async function walletInitialized() {
10361026 }
10371027 }
10381028}
1039-
1040- window . addEventListener ( 'load' , async ( ) => {
1041- if ( ! isAnyWebInstall ( ) ) {
1042- return
1043- }
1044-
1045- getElement ( 'installed' ) . innerHTML = 'installed'
1046- if ( window . localStorage . getItem ( '__FLUENT_USE_MODERN_PROVIDER_API__' ) ) {
1047- getElement ( 'installed-section' ) . style . display = 'block'
1048- }
1049-
1050- if ( isAnyWebInstall ( ) ) {
1051- console . log ( 'DApp 已经检查到OK了' )
1052- provider . request ( { method : 'anyweb_version' } ) . then ( ( version ) => {
1053- getElement ( 'version' ) . innerHTML = version
1054- } )
1055- } else {
1056- alert ( '找不到AnyWeb SDK, 请检查是否正确配置' )
1057- }
1058- } )
0 commit comments