1
- import { faLinkSlash } from '@fortawesome/free-solid-svg-icons' ;
2
- import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' ;
3
- import { useEffect , useState } from 'react' ;
4
- import WalletApi , { WalletKeys } from '../../services/connectors/wallet.connector' ;
5
- import { abbreviateAddress } from '../../services/utils.services' ;
6
- import WalletSelectorModalComponent from './wallet-selector-modal/wallet-selector-modal.component' ;
7
- import './wallet-selector.component.scss' ;
1
+ import { faLinkSlash } from "@fortawesome/free-solid-svg-icons" ;
2
+ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome" ;
3
+ import { useEffect , useState } from "react" ;
4
+ import Spinner from "src/pages/Airdrop/components/Spinner" ;
5
+ import WalletApi , {
6
+ WalletKeys ,
7
+ } from "../../services/connectors/wallet.connector" ;
8
+ import { abbreviateAddress } from "../../services/utils.services" ;
9
+ import WalletSelectorModalComponent from "./wallet-selector-modal/wallet-selector-modal.component" ;
10
+ import "./wallet-selector.component.scss" ;
8
11
9
12
interface Params {
10
13
connectedWallet : WalletApi | undefined ;
11
14
connectWallet : ( walletKey ?: WalletKeys ) => void ;
12
15
wrongNetwork : boolean | undefined ;
13
16
}
14
17
15
- function WalletSelectorComponent ( { connectedWallet, connectWallet, wrongNetwork } : Params ) {
18
+ function WalletSelectorComponent ( {
19
+ connectedWallet,
20
+ connectWallet,
21
+ wrongNetwork,
22
+ } : Params ) {
16
23
const [ modalVisible , setModalVisible ] = useState ( false ) ;
17
24
const [ walletMenuVisible , setWalletMenuVisible ] = useState ( false ) ;
18
- const [ walletAddress , setWalletAddress ] = useState ( '' ) ;
19
- const [ walletIcon , setWalletIcon ] = useState ( '' ) ;
25
+ const [ walletAddress , setWalletAddress ] = useState ( "" ) ;
26
+ const [ walletIcon , setWalletIcon ] = useState ( "" ) ;
20
27
21
28
const disconnectWallet = ( ) => {
22
29
setWalletMenuVisible ( false ) ;
23
30
connectWallet ( ) ;
24
- }
31
+ } ;
25
32
26
33
const toggleWalletMenuVisible = ( ) => {
27
34
setWalletMenuVisible ( ! walletMenuVisible ) ;
28
- }
35
+ } ;
29
36
30
37
useEffect ( ( ) => {
31
38
async function init ( ) {
32
39
if ( connectedWallet ) {
33
40
if ( connectedWallet . wallet ?. api ) {
34
- const addr = abbreviateAddress ( await connectedWallet . getAddress ( ) ) ;
41
+ const addr = abbreviateAddress (
42
+ await connectedWallet . getAddress ( )
43
+ ) ;
35
44
setWalletAddress ( addr ) ;
36
45
setWalletIcon ( connectedWallet . wallet . icon ) ;
37
46
setModalVisible ( false ) ;
38
47
}
39
48
} else {
40
- setWalletAddress ( '' ) ;
49
+ setWalletAddress ( "" ) ;
41
50
setModalVisible ( false ) ;
42
51
}
43
52
}
44
53
45
54
init ( ) ;
46
55
} , [ connectedWallet ?. wallet ?. api , connectedWallet ] ) ;
47
56
48
- const Connected = ( ) => (
49
- < div className = "wallet-connected" onClick = { ( ) => toggleWalletMenuVisible ( ) } >
50
- < img src = { walletIcon } className = 'wallet-icon' alt = 'wallet icon' > </ img >
51
- < p className = 'wallet-addr' > { walletAddress } </ p >
52
- </ div >
53
- )
57
+ const Connected = ( ) => {
58
+ return (
59
+ < div
60
+ className = "wallet-connected"
61
+ onClick = { ( ) => toggleWalletMenuVisible ( ) }
62
+ >
63
+ { walletIcon ? (
64
+ < >
65
+ < img
66
+ src = { walletIcon }
67
+ className = "wallet-icon"
68
+ alt = "wallet icon"
69
+ > </ img >
70
+ < p className = "wallet-addr" > { walletAddress } </ p >
71
+ </ >
72
+ ) : (
73
+ < div className = "wallet-info" >
74
+ Connecting < Spinner > </ Spinner >
75
+ </ div >
76
+ ) }
77
+ </ div >
78
+ ) ;
79
+ } ;
54
80
55
81
const NotConnected = ( ) => (
56
- < div className = "wallet-not-connected" onClick = { ( ) => setModalVisible ( true ) } >
82
+ < div
83
+ className = "wallet-not-connected"
84
+ onClick = { ( ) => setModalVisible ( true ) }
85
+ >
57
86
< p > Connect</ p >
58
87
</ div >
59
- )
88
+ ) ;
60
89
61
90
const WrongNetwork = ( ) => (
62
- < div className = { "wallet-wrong" } onClick = { ( ) => toggleWalletMenuVisible ( ) } >
91
+ < div
92
+ className = { "wallet-wrong" }
93
+ onClick = { ( ) => toggleWalletMenuVisible ( ) }
94
+ >
63
95
< p > WRONG NETWORK</ p >
64
96
</ div >
65
- )
97
+ ) ;
66
98
67
99
return (
68
- < div className = 'wallet-selector-container' >
69
- < WalletSelectorModalComponent modalVisible = { modalVisible } setModalVisible = { setModalVisible } connectedWallet = { connectedWallet } connectWallet = { connectWallet } />
70
- < div className = 'wallet-selector' >
71
- { wrongNetwork ? < WrongNetwork /> : ( connectedWallet ?. wallet ?. api ? < Connected /> : < NotConnected /> ) }
100
+ < div className = "wallet-selector-container" >
101
+ < WalletSelectorModalComponent
102
+ modalVisible = { modalVisible }
103
+ setModalVisible = { setModalVisible }
104
+ connectedWallet = { connectedWallet }
105
+ connectWallet = { connectWallet }
106
+ />
107
+ < div className = "wallet-selector" >
108
+ { wrongNetwork ? (
109
+ < WrongNetwork />
110
+ ) : connectedWallet ?. wallet ?. api ? (
111
+ < Connected />
112
+ ) : (
113
+ < NotConnected />
114
+ ) }
72
115
</ div >
73
- < div className = { 'wallet-menu' + ( connectedWallet ?. wallet ?. api && walletMenuVisible ? '' : ' hidden' ) } >
74
- < p onClick = { disconnectWallet } > < FontAwesomeIcon icon = { faLinkSlash } /> Disconnect</ p >
116
+ < div
117
+ className = {
118
+ "wallet-menu" +
119
+ ( connectedWallet ?. wallet ?. api && walletMenuVisible
120
+ ? ""
121
+ : " hidden" )
122
+ }
123
+ >
124
+ < p onClick = { disconnectWallet } >
125
+ < FontAwesomeIcon icon = { faLinkSlash } />
126
+ Disconnect
127
+ </ p >
75
128
</ div >
76
129
</ div >
77
- )
130
+ ) ;
78
131
}
79
132
80
- export default WalletSelectorComponent ;
133
+ export default WalletSelectorComponent ;
0 commit comments