Skip to content

Commit 1a44300

Browse files
Merge branch 'test' of github.com:CoNET-project/SilentPassUI into test
2 parents 240a9f9 + 65ae7d3 commit 1a44300

File tree

17 files changed

+537
-107
lines changed

17 files changed

+537
-107
lines changed

src/App.tsx

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,18 @@ import Transfer from './pages/Transfer';
2626
global.Buffer = require('buffer').Buffer;
2727

2828
function App() {
29-
const { setProfiles, setMiningData, allRegions, setClosestRegion, setaAllNodes, setServerIpAddress, setServerPort, _vpnTimeUsedInMin, setActivePassportUpdated, setActivePassport, setRandomSolanaRPC, randomSolanaRPC } = useDaemonContext();
29+
const { setProfiles, setMiningData, allRegions, setClosestRegion, setaAllNodes, setServerIpAddress, setServerPort, _vpnTimeUsedInMin, setActivePassportUpdated, setActivePassport, setRandomSolanaRPC } = useDaemonContext();
3030
const setSOlanaRPC = (allNodes: nodes_info[]) => {
3131
const randomIndex = Math.floor(Math.random() * (allNodes.length - 1))
3232
setRandomSolanaRPC(allNodes[randomIndex])
3333
}
3434
useEffect(() => {
3535
const handlePassport = async () => {
36+
if (!CoNET_Data?.profiles[0]?.keyID) return
37+
3638
await tryToRequireFreePassport();
37-
const info = await getCurrentPassportInfo();
39+
40+
const info = await getCurrentPassportInfo(CoNET_Data?.profiles[0]?.keyID);
3841

3942
const tmpData = CoNET_Data;
4043

@@ -66,7 +69,15 @@ function App() {
6669
}
6770

6871
const init = async () => {
69-
const vpnTimeUsedInMin = parseInt(localStorage.getItem("vpnTimeUsedInMin") || "0");
72+
let vpnTimeUsedInMin = 0
73+
try {
74+
const ss = await localStorage.getItem("vpnTimeUsedInMin")
75+
if (ss) {
76+
vpnTimeUsedInMin = parseInt(ss)
77+
}
78+
} catch (ex) {
79+
80+
}
7081
_vpnTimeUsedInMin.current = vpnTimeUsedInMin;
7182

7283
const queryParams = parseQueryParams(window.location.search);
@@ -86,7 +97,7 @@ function App() {
8697

8798
getAllNodes(allRegions, setClosestRegion, (allNodes: nodes_info[]) => {
8899
setSOlanaRPC(allNodes)
89-
setaAllNodes(allNodes)
100+
setaAllNodes(allNodes)
90101
const randomIndex = Math.floor(Math.random() * (allNodes.length - 1))
91102
setRandomSolanaRPC(allNodes[randomIndex])
92103
if (!CoNET_Data || !CoNET_Data?.profiles) {
@@ -113,8 +124,8 @@ function App() {
113124
console.log(ex)
114125
}
115126
};
116-
117-
if (!window?.webkit) {
127+
//@ts-ignore
128+
if (!window?.webkit && !window?.Android) {
118129
_getServerIpAddress();
119130
}
120131
}, []);

src/api/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,20 @@ export const getServerIpAddress = async (): Promise<AxiosResponse<any>> => {
4242
const response = await api.get("/ipaddress");
4343
return response;
4444
} catch (error) {
45-
console.error("Error fetching regions:", error);
45+
console.error("Error fetching ipaddress:", error);
4646
throw error;
4747
}
4848
};
4949

5050
export const joinSpClub = async (
5151
conetProfile: profile,
52-
solanaProfile: profile
52+
solanaProfile: profile,
53+
referrer: string
5354
) => {
5455
const message = JSON.stringify({
5556
walletAddress: conetProfile.keyID,
5657
solanaWallet: solanaProfile.keyID,
57-
referrer: "",
58+
referrer: referrer,
5859
});
5960

6061
const wallet = new ethers.Wallet(conetProfile.privateKeyArmor);

src/components/AccountList/ReferralProgram.tsx

Lines changed: 58 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,16 @@
1-
import { useState } from 'react';
1+
import { useEffect, useState } from 'react';
22
import './index.css';
33
import Separator from '../Separator';
4-
import CopyAccountInfo from './CopyAccountInfo';
54
import { useDaemonContext } from '../../providers/DaemonProvider';
65
import Skeleton from '../Skeleton';
76

8-
import { ReactComponent as ConetToken } from './assets/conet-token.svg';
9-
import { ReactComponent as ConetEthToken } from './assets/conet-eth-token.svg';
10-
import { ReactComponent as SolanaToken } from './assets/solana-token.svg';
11-
import { ReactComponent as SpToken } from './assets/sp-token.svg';
12-
import PassportInfo from '../PassportInfo';
13-
import SelectActivePassportPopup from '../SelectActivePassportPopup';
14-
import { refreshSolanaBalances, storeSystemData } from '../../services/wallets';
15-
import { CoNET_Data } from '../../utils/globals';
16-
import { useNavigate } from 'react-router-dom';
177
import { ethers } from 'ethers';
188

199
import { ReactComponent as VisibilityOnIcon } from "./assets/visibility-on.svg";
2010
import { ReactComponent as VisibilityOffIcon } from "./assets/visibility-off.svg";
11+
import { getPassportTitle } from '../../utils/utils';
12+
import { currentPageInvitees, setCurrentPageInvitees } from '../../utils/globals';
13+
import { getRefereesPage } from '../../services/wallets';
2114

2215
const SP_EARNED_FROM_REFERRAL = 10
2316

@@ -27,6 +20,30 @@ export default function ReferralProgram() {
2720

2821
const [isAddressHidden, setIsAddressHidden] = useState(true);
2922
const [copied, setCopied] = useState(false);
23+
const [shouldRerender, setShouldRerender] = useState(false);
24+
25+
26+
const handlePreviousPage = async () => {
27+
if (currentPageInvitees > 0) {
28+
setCurrentPageInvitees(currentPageInvitees - 1)
29+
await getRefereesPage(profiles[0], currentPageInvitees)
30+
setShouldRerender(true)
31+
}
32+
}
33+
34+
const handleNextPage = async () => {
35+
if (currentPageInvitees < Math.ceil(profiles?.[0]?.spClub?.totalReferees / 100)) {
36+
setCurrentPageInvitees(currentPageInvitees + 1)
37+
await getRefereesPage(profiles[0], currentPageInvitees)
38+
setShouldRerender(true)
39+
}
40+
}
41+
42+
useEffect(() => {
43+
if (shouldRerender) {
44+
setShouldRerender(false)
45+
}
46+
}, [shouldRerender])
3047

3148
function handleCopy() {
3249
navigator.clipboard.writeText(profiles?.[0]?.keyID);
@@ -42,9 +59,9 @@ export default function ReferralProgram() {
4259
}
4360

4461
return (
45-
<div className={`account-wrapper ${isOpen ? 'active' : ''}`}>
46-
{/* <div className="account-main-card" onClick={() => setIsOpen((prev) => !prev)}> */}
47-
<div className="disabled account-main-card">
62+
<div className={`account-wrapper fit-content ${isOpen ? 'active' : ''}`}>
63+
<div className="account-main-card" onClick={() => setIsOpen((prev) => !prev)}>
64+
{/* <div className="disabled account-main-card"> */}
4865
<div className="name">
4966
<h3>Referral Program</h3>
5067
<img height='16px' width='16px' className="chevron" src="./assets/right-chevron.svg" />
@@ -56,7 +73,7 @@ export default function ReferralProgram() {
5673
{profiles?.[0]?.keyID ?
5774
<>
5875
<div className="copy-text">
59-
<p>Wallet Address</p>
76+
<p>Copy this wallet address to invite your friends to Silent Pass</p>
6077
{
6178
isAddressHidden ?
6279
<div style={{ filter: 'blur(3px)' }}>
@@ -97,32 +114,46 @@ export default function ReferralProgram() {
97114
</div>
98115
<div style={{ marginLeft: '16px' }}>
99116
<div style={{ display: 'flex', alignItems: 'center', gap: '4px' }}>
100-
<p>Referees</p>
117+
<p>Invitees</p>
101118
</div>
102119
<p>{profiles?.[0]?.spClub?.referees?.length}</p>
103120
</div>
104121
<div style={{ marginLeft: '16px' }}>
105122
<div style={{ display: 'flex', alignItems: 'center', gap: '4px' }}>
106123
<p>$SP</p>
107124
</div>
108-
<p>{(Number(profiles?.[0]?.spClub?.totalReferees) * SP_EARNED_FROM_REFERRAL) || 0}</p>
125+
<p>0</p>
109126
</div>
110127
</div>
111128

112129
<Separator />
113130

114-
<div className="info-wrapper" style={{ maxHeight: '200px', overflowY: 'auto', }}>
115-
<p>History</p>
116-
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: '8px', width: '100%', paddingLeft: '16px' }}>
117-
{profiles?.[0]?.spClub?.referees
118-
? profiles?.[0]?.spClub.referees?.map((referee: any) =>
119-
<div style={{ display: 'flex', flexDirection: 'row', alignItems: 'center', width: '100%', gap: '8px' }}>
120-
<p style={{ width: 'auto', fontSize: '16px', color: '#989899', fontWeight: 400 }}>{referee?.slice(0, 5) + '...' + referee?.slice(-5)}</p>
121-
<p style={{ width: 'auto', fontSize: '16px', color: '#9FBFE5FE', fontWeight: 400 }}>+ {SP_EARNED_FROM_REFERRAL} $SP</p>
122-
</div>
123-
)
131+
<div className="info-wrapper" style={{ display: 'flex', flexDirection: 'column', justifyContent: 'space-between', gap: '16px' }}>
132+
<p>Invitees</p>
133+
134+
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: '8px', width: '100%', paddingLeft: '16px', maxHeight: '100px', overflowY: 'auto', paddingRight: '10px' }}>
135+
{profiles?.[0]?.spClub
136+
?
137+
profiles?.[0].spClub?.totalReferees > 0 ?
138+
profiles?.[0]?.spClub.referees?.map((referee: any) =>
139+
<div style={{ display: 'flex', flexDirection: 'row', alignItems: 'center', width: '100%', gap: '8px' }}>
140+
<p style={{ width: 'auto', fontSize: '16px', color: '#FFFFFF', fontWeight: 400 }}>{getPassportTitle(referee?.activePassport)}</p>
141+
<p style={{ width: 'auto', fontSize: '16px', color: '#989899', fontWeight: 400 }}>{referee?.walletAddress?.slice(0, 5) + '...' + referee?.walletAddress?.slice(-5)}</p>
142+
</div>
143+
) :
144+
<p>No invitees</p>
124145
: <Skeleton width={'100%'} height={'20px'} />}
125146
</div>
147+
148+
<div style={{ width: '100%', display: 'flex', flexDirection: 'row', alignItems: 'center', justifyContent: 'center', gap: '8px' }}>
149+
<div style={{ cursor: 'pointer' }} onClick={handlePreviousPage}>
150+
<img src="/assets/chevron-blue.svg" alt="Back" width={16} height={16} />
151+
</div>
152+
<div>{currentPageInvitees + 1} of {Math.ceil(profiles?.[0]?.spClub?.totalReferees / 100)}</div>
153+
<div style={{ cursor: 'pointer' }} onClick={handleNextPage}>
154+
<img src="/assets/chevron-blue.svg" alt="Back" width={16} height={16} style={{ transform: 'rotate(180deg)' }} />
155+
</div>
156+
</div>
126157
</div>
127158
</div>
128159
</div>

0 commit comments

Comments
 (0)