Skip to content

Commit f037cf8

Browse files
committed
feat (WIP): join sp club
1 parent d611896 commit f037cf8

File tree

4 files changed

+101
-4
lines changed

4 files changed

+101
-4
lines changed

src/api/index.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import axios, { AxiosResponse } from "axios";
2+
import { ethers } from "ethers";
3+
import { apiv4_endpoint } from "../utils/constants";
4+
import { getCONET_api_health, postToEndpoint } from "../utils/utils";
25

36
// Create an Axios instance with common configurations
47
const api = axios.create({
@@ -43,3 +46,30 @@ export const getServerIpAddress = async (): Promise<AxiosResponse<any>> => {
4346
throw error;
4447
}
4548
};
49+
50+
export const joinSpClub = async (
51+
conetProfile: profile,
52+
solanaProfile: profile
53+
) => {
54+
const message = JSON.stringify({
55+
walletAddress: conetProfile.keyID,
56+
// solanaWallet: solanaProfile.keyID,
57+
});
58+
59+
const wallet = new ethers.Wallet(conetProfile.privateKeyArmor);
60+
const signMessage = await wallet.signMessage(message);
61+
62+
const sendData = {
63+
message,
64+
signMessage,
65+
};
66+
67+
if (await getCONET_api_health()) {
68+
const url = `${apiv4_endpoint}spclub`;
69+
let result = await postToEndpoint(url, true, sendData);
70+
71+
return result;
72+
}
73+
74+
return false;
75+
};

src/components/AccountList/SpClub.tsx

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,38 @@ import { useState } from 'react'
22

33
import "./index.css";
44
import SpClubCongratsPopup from '../SpClubCongratsPopup';
5+
import SimpleLoadingRing from '../SimpleLoadingRing';
6+
import { joinSpClub } from '../../api';
7+
import { useDaemonContext } from '../../providers/DaemonProvider';
58

69
export default function SpClub() {
710
const [isOpen, setIsOpen] = useState<boolean>(false);
811
const [walletAddress, setWalletAddress] = useState('');
912
const [isCongratsPopupOpen, setIsCongratsPopupOpen] = useState<boolean>(false);
1013
const [isLoading, setIsLoading] = useState<boolean>(false);
1114

15+
const { profiles } = useDaemonContext();
16+
17+
const handleJoinClub = async () => {
18+
setIsLoading(true)
19+
20+
try {
21+
const result = await joinSpClub(profiles[0], profiles[1]);
22+
23+
if (result !== false)
24+
setIsCongratsPopupOpen(true)
25+
} catch (error) {
26+
console.log(error);
27+
}
28+
29+
setTimeout(() => setIsLoading(false), 2000)
30+
}
31+
1232
return (
1333
<>
1434
<div className={`account-wrapper referral-program ${isOpen ? 'active' : ''}`}>
15-
{/* <div className="account-main-card" onClick={() => setIsOpen((prev) => !prev)}> */}
16-
<div className="disabled account-main-card">
35+
<div className="account-main-card" onClick={() => setIsOpen((prev) => !prev)}>
36+
{/* <div className="disabled account-main-card"> */}
1737
<div className="name">
1838
<h3>Join SP Club</h3>
1939
<img height='16px' width='16px' className="chevron" src="./assets/right-chevron.svg" />
@@ -41,7 +61,11 @@ export default function SpClub() {
4161
<p style={{ width: '100%', textAlign: 'center', fontSize: '16px' }}>Get Silent Pass Passport and join the club</p>
4262
</div>
4363

44-
<button><p>Join Club</p></button>
64+
<button onClick={handleJoinClub}>
65+
{isLoading ? <SimpleLoadingRing /> :
66+
<p>Join Club</p>
67+
}
68+
</button>
4569
</div>
4670
</div>
4771
</div>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import styled, { keyframes } from 'styled-components';
2+
3+
const rotationClock = keyframes`
4+
from {
5+
transform: rotate(0deg);
6+
}
7+
to {
8+
transform: rotate(360deg);
9+
}
10+
`;
11+
12+
const LoadingRingContainer = styled.div`
13+
display: flex;
14+
flex-direction: row !important;
15+
justify-content: center !important;
16+
align-items: center !important;
17+
width: 100% !important;
18+
`;
19+
20+
const RotatingImage = styled.img`
21+
22+
`;
23+
24+
const RotationClock = styled(RotatingImage)`
25+
animation: ${rotationClock} 2s infinite linear;
26+
`;
27+
28+
export default function SimpleLoadingRing() {
29+
return (
30+
<LoadingRingContainer>
31+
<RotationClock src="/assets/dentro.svg" />
32+
</LoadingRingContainer>
33+
);
34+
}

src/utils/utils.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import bs58 from "bs58";
22
import { Keypair } from "@solana/web3.js";
3-
import { XMLHttpRequestTimeout } from "./constants";
3+
import { apiv4_endpoint, XMLHttpRequestTimeout } from "./constants";
44
import contracts from "./contracts";
55

66
export const customJsonStringify = (item: any) => {
@@ -230,3 +230,12 @@ export function isValidSolanaBase58PrivateKey(base58Key: string) {
230230
return false;
231231
}
232232
}
233+
234+
export const getCONET_api_health = async () => {
235+
const url = `${apiv4_endpoint}health`;
236+
const result: any = await postToEndpoint(url, false, null);
237+
if (result?.health === true) {
238+
return true;
239+
}
240+
return false;
241+
};

0 commit comments

Comments
 (0)