@@ -7,7 +7,7 @@ import classNames from 'classnames';
77
88import { Address } from '../address' ;
99import { CryptoPrice } from '../crypto-price' ;
10- import { useProvider } from '../hooks' ;
10+ import { useConnection , useProvider } from '../hooks' ;
1111import useIntl from '../hooks/useIntl' ;
1212import { fillWithPrefix , writeCopyText } from '../utils' ;
1313import { ChainSelect } from './chain-select' ;
@@ -57,6 +57,7 @@ export const ConnectButton: React.FC<ConnectButtonProps> = (props) => {
5757 const { wrapSSR, hashId } = useStyle ( prefixCls ) ;
5858 const [ messageApi , contextHolder ] = message . useMessage ( ) ;
5959 const [ showMenu , setShowMenu ] = useState ( false ) ;
60+ const [ signed , setSigned ] = useState ( false ) ;
6061
6162 const { coverAddress = true } = typeof balance !== 'object' ? { coverAddress : true } : balance ;
6263 const needSign = ! ! sign ?. signIn && account ?. status === ConnectStatus . Connected ;
@@ -99,6 +100,7 @@ export const ConnectButton: React.FC<ConnectButtonProps> = (props) => {
99100 try {
100101 if ( needSign ) {
101102 await sign ?. signIn ?.( account ?. address ) ;
103+ setSigned ( true ) ;
102104 }
103105 } catch ( error : any ) {
104106 messageApi . error ( error . message ) ;
@@ -162,6 +164,10 @@ export const ConnectButton: React.FC<ConnectButtonProps> = (props) => {
162164 ) ;
163165 }
164166
167+ const unsigned = needSign && ! signed ;
168+
169+ console . log ( 'unsigned:' , unsigned , account ?. status ) ;
170+
165171 const buttonInnerText = (
166172 < div className = { `${ prefixCls } -content` } >
167173 < div className = { `${ prefixCls } -content-inner` } >
@@ -196,6 +202,42 @@ export const ConnectButton: React.FC<ConnectButtonProps> = (props) => {
196202 } }
197203 onDisconnectClick = { onDisconnectClick }
198204 onOpenProfileClick = { ( ) => setProfileOpen ( true ) }
205+ onSignInClick = { ( ) => {
206+ if ( ! sign ?. signIn ) {
207+ return ;
208+ }
209+
210+ console . log ( 'onSignInClick:' , account , needSign , signed ) ;
211+ if ( signed ) {
212+ return ;
213+ }
214+
215+ if ( account ?. status === ConnectStatus . Signed ) {
216+ setSigned ( true ) ;
217+ return ;
218+ }
219+
220+ // If account is not connected, we need to sign in
221+ // If account is connected but not signed, we also need to sign in
222+ console . log ( 'signIn:' , account ?. address , needSign ) ;
223+ if ( account ?. status === ConnectStatus . Connected && signed ) {
224+ return ;
225+ }
226+
227+ // If account is not connected, we need to sign in
228+ // If account is connected but not signed, we also need to sign in
229+ console . log ( 'signIn:' , account ?. address , needSign ) ;
230+ if ( account && needSign ) {
231+ sign
232+ . signIn ?.( account . address ! )
233+ . then ( ( ) => {
234+ setSigned ( true ) ;
235+ } )
236+ . catch ( ( error ) => {
237+ messageApi . error ( error . message ) ;
238+ } ) ;
239+ }
240+ } }
199241 __hashId__ = { hashId }
200242 >
201243 { buttonInnerText }
0 commit comments