Skip to content

Commit 28dfcc0

Browse files
committed
feat: show solana wallet in wallets page
1 parent 2e698ce commit 28dfcc0

File tree

8 files changed

+50
-34
lines changed

8 files changed

+50
-34
lines changed

src/App.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { parseQueryParams } from "./utils/utils";
2323
global.Buffer = require('buffer').Buffer;
2424

2525
function App() {
26-
const { setProfile, setMiningData, allRegions, setClosestRegion, setaAllNodes, setServerIpAddress, setServerPort, _vpnTimeUsedInMin } = useDaemonContext();
26+
const { setProfiles, setMiningData, allRegions, setClosestRegion, setaAllNodes, setServerIpAddress, setServerPort, _vpnTimeUsedInMin } = useDaemonContext();
2727

2828
useEffect(() => {
2929
const handlePassport = async () => {
@@ -37,7 +37,7 @@ function App() {
3737
}
3838

3939
tmpData.profiles[0] = {
40-
...tmpData.profiles[0],
40+
...tmpData?.profiles[0],
4141
activeFreePassport: {
4242
nftID: info?.nftIDs?.[0]?.toString(),
4343
expires: info?.expires?.[0]?.toString(),
@@ -49,7 +49,7 @@ function App() {
4949

5050
if (!CoNET_Data) return;
5151

52-
setProfile(CoNET_Data.profiles[0]);
52+
setProfiles(CoNET_Data?.profiles);
5353
}
5454

5555
const _getServerIpAddress = async () => {
@@ -77,7 +77,7 @@ function App() {
7777
}
7878

7979
await createOrGetWallet(secretPhrase);
80-
listenProfileVer(setProfile);
80+
listenProfileVer(setProfiles);
8181

8282
if (!window?.webkit) {
8383
_getServerIpAddress();

src/components/AccountList/index.tsx

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { getRemainingTime } from '../../utils/utils';
1414

1515
export default function AccountList() {
1616
const [openAccountList, setOpenAccountList] = useState<string[]>([]);
17-
const { profile } = useDaemonContext();
17+
const { profiles } = useDaemonContext();
1818

1919
function toggleAccount(accountAddress: string) {
2020
setOpenAccountList((prev) => (
@@ -24,8 +24,8 @@ export default function AccountList() {
2424

2525
return (
2626
<div className="account-list">
27-
<div className={`account-wrapper ${openAccountList.includes(profile?.keyID) ? 'active' : ''}`}>
28-
<div className="account-main-card" onClick={() => toggleAccount(profile?.keyID)}>
27+
<div className={`account-wrapper ${openAccountList.includes(profiles?.[0]?.keyID) ? 'active' : ''}`}>
28+
<div className="account-main-card" onClick={() => toggleAccount(profiles?.[0]?.keyID)}>
2929
<div>
3030
<h3>Main Wallet</h3>
3131
<img className="chevron" src="./assets/right-chevron.svg" />
@@ -39,14 +39,14 @@ export default function AccountList() {
3939
<ConetToken />
4040
<p>$CONET</p>
4141
</div>
42-
<p>{profile?.tokens?.conetDepin?.balance || (0.0).toFixed(6)}</p>
42+
<p>{profiles?.[0]?.tokens?.conetDepin?.balance || (0.0).toFixed(6)}</p>
4343
</div>
4444
<div>
4545
<div style={{ display: 'flex', alignItems: 'center', gap: '4px' }}>
4646
<ConetEthToken />
4747
<p>$ETH</p>
4848
</div>
49-
<p>{profile?.tokens?.conet_eth?.balance || (0.0).toFixed(6)}</p>
49+
<p>{profiles?.[0]?.tokens?.conet_eth?.balance || (0.0).toFixed(6)}</p>
5050
</div>
5151
</div>
5252
<Separator />
@@ -55,14 +55,14 @@ export default function AccountList() {
5555
<div style={{ display: 'flex', flexDirection: 'row', alignItems: 'center' }}>
5656
<p>Freemium</p>
5757
{
58-
profile?.activeFreePassport?.expires ?
59-
<p>{getRemainingTime(profile?.activeFreePassport?.expires)}</p>
58+
profiles?.[0]?.activeFreePassport?.expires ?
59+
<p>{getRemainingTime(profiles?.[0]?.activeFreePassport?.expires)}</p>
6060
: <Skeleton width='50px' height='20px' />
6161
}
6262
</div>
6363
</div>
6464
<Separator />
65-
<CopyAccountInfo wallet={profile} />
65+
<CopyAccountInfo wallet={profiles?.[0]} />
6666
</div>
6767
</div>
6868

@@ -75,8 +75,7 @@ export default function AccountList() {
7575
</div>
7676

7777
<div className={`account-wrapper solana ${openAccountList.includes("123") ? 'active' : ''}`}>
78-
{/* <div className="disabled account-main-card" onClick={() => toggleAccount("123")}> */}
79-
<div className="disabled account-main-card">
78+
<div className="account-main-card" onClick={() => toggleAccount("123")}>
8079
<div>
8180
<h3>Solana Wallet</h3>
8281
<img className="chevron" src="./assets/right-chevron.svg" />
@@ -91,18 +90,18 @@ export default function AccountList() {
9190
<SpToken />
9291
<p>$SP</p>
9392
</div>
94-
<p>0</p>
93+
<p>{profiles?.[1]?.tokens?.conetDepin?.balance || (0.0).toFixed(6)}</p>
9594
</div>
9695
<div>
9796
<div style={{ display: 'flex', alignItems: 'center', gap: '4px' }}>
9897
<SolanaToken />
9998
<p>$SOL</p>
10099
</div>
101-
<p>0</p>
100+
<p>{profiles?.[1]?.tokens?.conetDepin?.balance || (0.0).toFixed(6)}</p>
102101
</div>
103102
</div>
104103
<Separator />
105-
<CopyAccountInfo wallet={profile} />
104+
<CopyAccountInfo wallet={profiles?.[1]} />
106105
</div>
107106
</div>
108107
</div>

src/components/PassportInfo/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Skeleton from "../Skeleton";
55

66
const PassportInfo = () => {
77
const navigate = useNavigate();
8-
const { profile } = useDaemonContext();
8+
const { profiles } = useDaemonContext();
99

1010
return (
1111
<div className="main-card">
@@ -16,8 +16,8 @@ const PassportInfo = () => {
1616
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'end' }}>
1717
<span>Expiration date</span>
1818
{
19-
profile?.activeFreePassport?.expires ?
20-
<p>{getRemainingTime(profile?.activeFreePassport?.expires)}</p>
19+
profiles?.[0]?.activeFreePassport?.expires ?
20+
<p>{getRemainingTime(profiles?.[0]?.activeFreePassport?.expires)}</p>
2121
: <Skeleton width='50px' height='20px' />
2222
}
2323
</div>

src/pages/Home/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ const RenderButton = ({ errorStartingSilentPass, handleTogglePower, isConnection
8787

8888

8989
const Home = () => {
90-
const { profile, sRegion, setSRegion, setAllRegions, allRegions, setIsRandom, getAllNodes, closestRegion, _vpnTimeUsedInMin } = useDaemonContext();
90+
const { profiles, sRegion, setSRegion, setAllRegions, allRegions, setIsRandom, getAllNodes, closestRegion, _vpnTimeUsedInMin } = useDaemonContext();
9191
const [power, setPower] = useState<boolean>(false);
9292
const [isInitialLoading, setIsInitialLoading] = useState<boolean>(true);
9393
const [isConnectionLoading, setIsConnectionLoading] = useState<boolean>(false)
@@ -275,7 +275,7 @@ const Home = () => {
275275
<img src="/assets/header-title.svg"></img>
276276
</div>
277277

278-
<RenderButton profile={profile} errorStartingSilentPass={errorStartingSilentPass} isConnectionLoading={isConnectionLoading} power={power} handleTogglePower={handleTogglePower} _vpnTimeUsedInMin={_vpnTimeUsedInMin.current} />
278+
<RenderButton profile={profiles?.[0]} errorStartingSilentPass={errorStartingSilentPass} isConnectionLoading={isConnectionLoading} power={power} handleTogglePower={handleTogglePower} _vpnTimeUsedInMin={_vpnTimeUsedInMin.current} />
279279

280280
<CopyProxyInfo />
281281

src/pages/Settings/index.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ export default function Settings() {
3636
const navigate = useNavigate();
3737
const [theme, setTheme] = useState<'light' | 'dark'>('light');
3838

39-
const { profile } = useDaemonContext();
40-
4139
function handleChangeTheme() {
4240
setTheme((prev) => prev === 'light' ? 'dark' : 'light')
4341
}

src/providers/DaemonProvider.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ type DaemonContext = {
1111
setIsRandom: (val: boolean) => void;
1212
miningData: any;
1313
setMiningData: (data: any) => void;
14-
profile: any;
15-
setProfile: (profile: any) => void;
14+
profiles: any;
15+
setProfiles: (profiles: any) => void;
1616
isMiningUp: boolean;
1717
setIsMiningUp: (val: boolean) => void;
1818
setaAllNodes: (data: nodes_info[]) => void
@@ -41,8 +41,8 @@ const defaultContextValue: DaemonContext = {
4141
setIsRandom: () => { },
4242
miningData: null,
4343
setMiningData: () => { },
44-
profile: null,
45-
setProfile: () => { },
44+
profiles: null,
45+
setProfiles: () => { },
4646
isMiningUp: false,
4747
setIsMiningUp: () => { },
4848
setaAllNodes: () => { },
@@ -69,7 +69,7 @@ export function DaemonProvider({ children }: DaemonProps) {
6969
const [allRegions, setAllRegions] = useState<Region[]>([]);
7070
const [closestRegion, setClosestRegion] = useState<any>(null);
7171
const [miningData, setMiningData] = useState<any>(null);
72-
const [profile, setProfile] = useState<any>(null);
72+
const [profiles, setProfiles] = useState<any>(null);
7373
const [isMiningUp, setIsMiningUp] = useState<boolean>(false);
7474
const [getAllNodes, setaAllNodes] = useState<nodes_info[]>([]);
7575
const [serverIpAddress, setServerIpAddress] = useState<string>(defaultContextValue.serverIpAddress);
@@ -86,7 +86,7 @@ export function DaemonProvider({ children }: DaemonProps) {
8686

8787

8888
return (
89-
<Daemon.Provider value={{ sRegion, setSRegion, allRegions, setAllRegions, closestRegion, setClosestRegion, isRandom, setIsRandom, miningData, setMiningData, profile, setProfile, isMiningUp, setIsMiningUp, getAllNodes, setaAllNodes, serverIpAddress, setServerIpAddress, serverPort, setServerPort, serverPac, setServerPac, _vpnTimeUsedInMin }}>
89+
<Daemon.Provider value={{ sRegion, setSRegion, allRegions, setAllRegions, closestRegion, setClosestRegion, isRandom, setIsRandom, miningData, setMiningData, profiles, setProfiles, isMiningUp, setIsMiningUp, getAllNodes, setaAllNodes, serverIpAddress, setServerIpAddress, serverPort, setServerPort, serverPac, setServerPac, _vpnTimeUsedInMin }}>
9090
{children}
9191
</Daemon.Provider>
9292
);

src/services/listeners.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { getFreePassportInfo, getVpnTimeUsed } from "./wallets";
1212

1313
let epoch = 0;
1414

15-
const listenProfileVer = async (callback: (profile: profile) => void) => {
15+
const listenProfileVer = async (callback: (profiles: profile[]) => void) => {
1616
epoch = await conetProvider.getBlockNumber();
1717

1818
conetProvider.on("block", async (block) => {
@@ -31,7 +31,7 @@ const listenProfileVer = async (callback: (profile: profile) => void) => {
3131

3232
await getVpnTimeUsed();
3333

34-
if (CoNET_Data?.profiles[0]) callback(CoNET_Data?.profiles[0]);
34+
if (CoNET_Data?.profiles[0]) callback(CoNET_Data?.profiles);
3535
}
3636
});
3737

src/services/wallets.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ async function deriveSolanaSeed(seed: any) {
4141
return hash.slice(0, 32); // Take the first 32 bytes as the private key
4242
}
4343

44+
const convertSecretKeyToPrivateKey = (secretKey: any) => {
45+
// Extract the first 32 bytes (private key)
46+
const privateKey = secretKey.slice(0, 32);
47+
48+
// Convert to a 64-character hex string (Ethereum format)
49+
const privateKeyHex = Buffer.from(privateKey).toString("hex");
50+
51+
return privateKeyHex;
52+
};
53+
4454
const createOrGetWallet = async (secretPhrase: string | null) => {
4555
await checkStorage();
4656

@@ -83,6 +93,10 @@ const createOrGetWallet = async (secretPhrase: string | null) => {
8393
acc?.mnemonic?.phrase
8494
);
8595

96+
const privateKeyHex = convertSecretKeyToPrivateKey(
97+
secondaryWallet.secretKey
98+
);
99+
86100
const profile2: profile = {
87101
tokens: initProfileTokens(),
88102
publicKeyArmor: secondaryWallet.publicKey.toString(),
@@ -94,7 +108,7 @@ const createOrGetWallet = async (secretPhrase: string | null) => {
94108
privateKeyArmor: key.privateKey,
95109
publicKeyArmor: key.publicKey,
96110
},
97-
privateKeyArmor: secondaryWallet.secretKey.toString(),
111+
privateKeyArmor: privateKeyHex,
98112
hdPath: null,
99113
index: 0,
100114
type: "solana",
@@ -116,6 +130,11 @@ const createOrGetWallet = async (secretPhrase: string | null) => {
116130
const secondaryWallet = await getSolanaKeypairFromMnemonic(
117131
tmpData.mnemonicPhrase
118132
);
133+
134+
const privateKeyHex = convertSecretKeyToPrivateKey(
135+
secondaryWallet.secretKey
136+
);
137+
119138
const key = await createGPGKey("", "", "");
120139

121140
const profile2: profile = {
@@ -129,7 +148,7 @@ const createOrGetWallet = async (secretPhrase: string | null) => {
129148
privateKeyArmor: key.privateKey,
130149
publicKeyArmor: key.publicKey,
131150
},
132-
privateKeyArmor: secondaryWallet.secretKey.toString(),
151+
privateKeyArmor: privateKeyHex,
133152
hdPath: null,
134153
index: 0,
135154
type: "solana",

0 commit comments

Comments
 (0)