Skip to content

Commit e91d6cf

Browse files
authored
Merge pull request #78 from TosiDrop/airdrop
fix/client: fix wallet connecting bug
2 parents 3a7f789 + 5cf4b22 commit e91d6cf

File tree

2 files changed

+95
-32
lines changed

2 files changed

+95
-32
lines changed

client/src/components/wallet-selector/wallet-selector.component.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@
4949
height: 100%;
5050
align-items: center;
5151
position: relative;
52+
color: var(--font-highlight);
53+
54+
.wallet-info {
55+
display: flex;
56+
flex-direction: row;
57+
align-items: center;
58+
& > *:first-child {
59+
margin-left: 10px;
60+
}
61+
}
5262

5363
.wallet-icon {
5464
width: 20px;
Lines changed: 85 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,133 @@
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";
811

912
interface Params {
1013
connectedWallet: WalletApi | undefined;
1114
connectWallet: (walletKey?: WalletKeys) => void;
1215
wrongNetwork: boolean | undefined;
1316
}
1417

15-
function WalletSelectorComponent({ connectedWallet, connectWallet, wrongNetwork }: Params) {
18+
function WalletSelectorComponent({
19+
connectedWallet,
20+
connectWallet,
21+
wrongNetwork,
22+
}: Params) {
1623
const [modalVisible, setModalVisible] = useState(false);
1724
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("");
2027

2128
const disconnectWallet = () => {
2229
setWalletMenuVisible(false);
2330
connectWallet();
24-
}
31+
};
2532

2633
const toggleWalletMenuVisible = () => {
2734
setWalletMenuVisible(!walletMenuVisible);
28-
}
35+
};
2936

3037
useEffect(() => {
3138
async function init() {
3239
if (connectedWallet) {
3340
if (connectedWallet.wallet?.api) {
34-
const addr = abbreviateAddress(await connectedWallet.getAddress());
41+
const addr = abbreviateAddress(
42+
await connectedWallet.getAddress()
43+
);
3544
setWalletAddress(addr);
3645
setWalletIcon(connectedWallet.wallet.icon);
3746
setModalVisible(false);
3847
}
3948
} else {
40-
setWalletAddress('');
49+
setWalletAddress("");
4150
setModalVisible(false);
4251
}
4352
}
4453

4554
init();
4655
}, [connectedWallet?.wallet?.api, connectedWallet]);
4756

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+
};
5480

5581
const NotConnected = () => (
56-
<div className="wallet-not-connected" onClick={() => setModalVisible(true)}>
82+
<div
83+
className="wallet-not-connected"
84+
onClick={() => setModalVisible(true)}
85+
>
5786
<p>Connect</p>
5887
</div>
59-
)
88+
);
6089

6190
const WrongNetwork = () => (
62-
<div className={"wallet-wrong"} onClick={() => toggleWalletMenuVisible()}>
91+
<div
92+
className={"wallet-wrong"}
93+
onClick={() => toggleWalletMenuVisible()}
94+
>
6395
<p>WRONG NETWORK</p>
6496
</div>
65-
)
97+
);
6698

6799
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+
)}
72115
</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>
75128
</div>
76129
</div>
77-
)
130+
);
78131
}
79132

80-
export default WalletSelectorComponent;
133+
export default WalletSelectorComponent;

0 commit comments

Comments
 (0)