Skip to content

Commit 6a034e1

Browse files
committed
mainBranch
1 parent a3fc09a commit 6a034e1

File tree

13 files changed

+523
-2032
lines changed

13 files changed

+523
-2032
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
"react-spring": "^9.7.4",
3131
"stream-http": "^3.2.0",
3232
"typescript": "^4.9.5",
33-
"web-vitals": "^2.1.4"
33+
"web-vitals": "^2.1.4",
34+
"bs58": "6.0.0"
3435
},
3536
"scripts": {
3637
"start": "react-scripts start",

src/components/AccountList/CopyAccountInfo.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { ReactComponent as VisibilityOffIcon } from "./assets/visibility-off.svg
88

99
let copyTimeoutId: NodeJS.Timeout;
1010

11+
1112
export default function CopyAccountInfo({ wallet }: any) {
1213
const [copied, setCopied] = useState({
1314
address: "",

src/components/AccountList/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ export default function AccountList() {
9090
<SpToken />
9191
<p>$SP</p>
9292
</div>
93-
<p>{profiles?.[1]?.tokens?.conetDepin?.balance || (0.0).toFixed(6)}</p>
93+
<p>{profiles?.[1]?.tokens?.SP?.balance || (0.0).toFixed(6)}</p>
9494
</div>
9595
<div>
9696
<div style={{ display: 'flex', alignItems: 'center', gap: '4px' }}>
9797
<SolanaToken />
9898
<p>$SOL</p>
9999
</div>
100-
<p>{profiles?.[1]?.tokens?.conetDepin?.balance || (0.0).toFixed(6)}</p>
100+
<p>{profiles?.[1]?.tokens?.solana?.balance || (0.0).toFixed(6)}</p>
101101
</div>
102102
</div>
103103
<Separator />

src/pages/Wallet/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default function Wallet() {
1515

1616
<div className="cta-buttons">
1717
<div className="highlight-2">
18-
<button className='disabled'>
18+
<button className='enable'>
1919
<img src="/assets/conet-outline-gray.svg" alt="Platform" />
2020
<p>Purchase Silent Pass Passport</p>
2121
</button>

src/services/listeners.ts

Lines changed: 135 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,25 @@ import {
44
conetDepinProvider,
55
conetProvider,
66
ethProvider,
7+
XMLHttpRequestTimeout,
8+
solanaRPC,
79
} from "../utils/constants";
810
import {
911
CoNET_Data,
1012
processingBlock,
1113
setCoNET_Data,
1214
setProcessingBlock,
15+
lastProceeeTime,
16+
setLastProceeeTime
1317
} from "../utils/globals";
1418
import contracts from "../utils/contracts";
1519
import { initProfileTokens } from "../utils/utils";
16-
import { getVpnTimeUsed } from "./wallets";
20+
import { getVpnTimeUsed } from "./wallets";
21+
import { Connection, PublicKey, Keypair } from "@solana/web3.js"
22+
import Bs58 from "bs58"
1723

1824
let epoch = 0;
25+
const SOLANA_CONNECTION = new Connection(solanaRPC)
1926

2027
const listenProfileVer = async (callback: (profiles: profile[]) => void) => {
2128
epoch = await conetProvider.getBlockNumber();
@@ -25,8 +32,10 @@ const listenProfileVer = async (callback: (profiles: profile[]) => void) => {
2532
epoch++;
2633

2734
if (processingBlock === true) return;
28-
29-
if (block % 10 === 0) {
35+
36+
const currentTime = new Date().getTime()
37+
// over 30 seconds!
38+
if (currentTime > lastProceeeTime + XMLHttpRequestTimeout ) {
3039
setProcessingBlock(true);
3140

3241
const profiles = CoNET_Data?.profiles;
@@ -36,20 +45,106 @@ const listenProfileVer = async (callback: (profiles: profile[]) => void) => {
3645
const runningList: any[] = [];
3746

3847
runningList.push(getProfileAssets(profiles[0]));
39-
48+
runningList.push(getSolanaAssets(profiles[1]))
4049
await Promise.all(runningList);
4150

4251
await getVpnTimeUsed();
4352

4453
if (CoNET_Data?.profiles[0]) callback(CoNET_Data?.profiles);
45-
46-
setProcessingBlock(false);
54+
setProcessingBlock(false)
55+
setLastProceeeTime(new Date().getTime())
4756
}
4857
}
4958
});
5059

5160
epoch = await conetProvider.getBlockNumber();
5261
};
62+
const scan_spl_balance = async (walletAddr: string, tokenAddress: string) => {
63+
try {
64+
const TOKEN_PROGRAM_ID = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"; // Solana SPL Token Program ID
65+
66+
const payload = {
67+
jsonrpc: "2.0",
68+
id: 1,
69+
method: "getTokenAccountsByOwner",
70+
params: [
71+
walletAddr,
72+
{ programId: TOKEN_PROGRAM_ID },
73+
{ encoding: "jsonParsed" },
74+
],
75+
};
76+
77+
const response = await fetch(solanaRPC, {
78+
method: "POST",
79+
headers: {
80+
"Content-Type": "application/json",
81+
},
82+
body: JSON.stringify(payload),
83+
});
84+
85+
if (!response.ok) {
86+
throw new Error(`HTTP error! Status: ${response.status}`);
87+
}
88+
89+
const data = await response.json();
90+
const tokenAccounts = data.result?.value ?? [];
91+
92+
for (let account of tokenAccounts) {
93+
const info = account.account.data.parsed.info;
94+
if (info.mint === tokenAddress) {
95+
return info.tokenAmount.uiAmount; // Return balance in tokens
96+
}
97+
}
98+
99+
return 0; // No balance found
100+
} catch (error) {
101+
console.error("Error fetching SPL balance:", error);
102+
return false;
103+
}
104+
};
105+
const getSolanaAssets = async (profile: profile) => {
106+
107+
const publciKey = new PublicKey(profile.keyID)
108+
const [balanceSo, balanceSP] = await Promise.all([
109+
SOLANA_CONNECTION.getBalance(publciKey),
110+
scan_spl_balance(profile.keyID, contracts.SP.address)
111+
])
112+
113+
if (profile.tokens?.solana) {
114+
const solanaObj = profile.tokens.solana
115+
profile.tokens.solana.balance =
116+
parseFloat(
117+
ethers.formatUnits(balanceSo.toString(), solanaObj.decimal).toString()
118+
).toFixed(6)
119+
} else {
120+
profile.tokens.solana = {
121+
balance:
122+
parseFloat(
123+
ethers.formatUnits(balanceSo.toString(), 9).toString()
124+
).toFixed(6),
125+
network: "Solana",
126+
decimal: 9,
127+
contract: "",
128+
name: "Solana",
129+
}
130+
}
131+
132+
if (profile.tokens?.SP) {
133+
const spOBJ = profile.tokens.SP
134+
profile.tokens.SP.balance = balanceSP ? balanceSP.toFixed(4): "0"
135+
} else {
136+
profile.tokens.SP = {
137+
balance: balanceSP ? balanceSP.toFixed(4): "0",
138+
network: "Solana",
139+
decimal: contracts.SP.decimal,
140+
contract: contracts.SP.address,
141+
name: "Solana",
142+
}
143+
}
144+
145+
146+
}
147+
53148

54149
const getProfileAssets = async (profile: profile) => {
55150
const key = profile.keyID;
@@ -59,45 +154,45 @@ const getProfileAssets = async (profile: profile) => {
59154
profile.tokens = initProfileTokens();
60155
}
61156

62-
const [cCNTP, conet, conetDepin, conet_eth, eth] = await Promise.all([
63-
scanCCNTP(key),
64-
scanCONETHolesky(key),
157+
const [conetDepin, conet_eth, eth] = await Promise.all([
158+
// scanCCNTP(key),
159+
// scanCONETHolesky(key),
65160
scanCONETDepin(key),
66161
scanConetETH(key),
67162
scanETH(key),
68163
]);
69164

70-
if (profile.tokens?.cCNTP) {
71-
profile.tokens.cCNTP.balance =
72-
cCNTP === false ? "" : parseFloat(ethers.formatEther(cCNTP)).toFixed(6);
73-
} else {
74-
profile.tokens.cCNTP = {
75-
balance:
76-
cCNTP === false
77-
? ""
78-
: parseFloat(ethers.formatEther(cCNTP)).toFixed(6),
79-
network: "CONET Holesky",
80-
decimal: 18,
81-
contract: contracts.ClaimableConetPoint.address,
82-
name: "cCNTP",
83-
};
84-
}
85-
86-
if (profile.tokens?.conet) {
87-
profile.tokens.conet.balance =
88-
conet === false ? "" : parseFloat(ethers.formatEther(conet)).toFixed(6);
89-
} else {
90-
profile.tokens.conet = {
91-
balance:
92-
conet === false
93-
? ""
94-
: parseFloat(ethers.formatEther(conet)).toFixed(6),
95-
network: "CONET Holesky",
96-
decimal: 18,
97-
contract: "",
98-
name: "conet",
99-
};
100-
}
165+
// if (profile.tokens?.cCNTP) {
166+
// profile.tokens.cCNTP.balance =
167+
// cCNTP === false ? "" : parseFloat(ethers.formatEther(cCNTP)).toFixed(6);
168+
// } else {
169+
// profile.tokens.cCNTP = {
170+
// balance:
171+
// cCNTP === false
172+
// ? ""
173+
// : parseFloat(ethers.formatEther(cCNTP)).toFixed(6),
174+
// network: "CONET Holesky",
175+
// decimal: 18,
176+
// contract: contracts.ClaimableConetPoint.address,
177+
// name: "cCNTP",
178+
// };
179+
// }
180+
181+
// if (profile.tokens?.conet) {
182+
// profile.tokens.conet.balance =
183+
// conet === false ? "" : parseFloat(ethers.formatEther(conet)).toFixed(6);
184+
// } else {
185+
// profile.tokens.conet = {
186+
// balance:
187+
// conet === false
188+
// ? ""
189+
// : parseFloat(ethers.formatEther(conet)).toFixed(6),
190+
// network: "CONET Holesky",
191+
// decimal: 18,
192+
// contract: "",
193+
// name: "conet",
194+
// };
195+
// }
101196

102197
if (profile.tokens?.conetDepin) {
103198
profile.tokens.conetDepin.balance =

src/services/mining.ts

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,6 @@ const startMiningV2 = async (
242242
const postData = await createConnectCmd(profile, connectNode);
243243
let first = true;
244244

245-
const balance = profile?.tokens?.cCNTP?.balance;
246-
cCNTPcurrentTotal = !balance ? 0 : parseFloat(balance);
247245

248246
if (!connectNode?.domain || !postData) {
249247
console.log("connectNode.domain or postData is empty");
@@ -296,26 +294,7 @@ const startMiningV2 = async (
296294
profile.tokens = initProfileTokens();
297295
}
298296

299-
if (!profile.tokens?.cCNTP) {
300-
profile.tokens.cCNTP = {
301-
balance: "0",
302-
network: "CONET Holesky",
303-
decimal: 18,
304-
contract: contracts.ClaimableConetPoint.address,
305-
name: "cCNTP",
306-
};
307-
}
308-
const index = Math.floor(Math.random() * entryNodes.length - 1);
309-
const entryNode = entryNodes[index];
310-
const kk = parseFloat(response.rate);
311-
response.rate = isNaN(kk) ? "" : kk.toFixed(8);
312-
response.currentCCNTP = (
313-
parseFloat(profile.tokens.cCNTP.balance || "0") - cCNTPcurrentTotal
314-
).toFixed(8);
315-
if (response.currentCCNTP < "0") {
316-
cCNTPcurrentTotal = parseFloat(profile.tokens.cCNTP.balance);
317-
response.currentCCNTP = "0";
318-
}
297+
319298
callback(response);
320299
// validator(response, profile, entryNode);
321300
return ["success", JSON.stringify(response)];

src/services/wallets.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import {
1212
} from "../utils/constants";
1313
import contracts from "../utils/contracts";
1414
import { CoNET_Data, setCoNET_Data } from "../utils/globals";
15-
import { Keypair } from "@solana/web3.js";
15+
import { Keypair, PublicKey } from "@solana/web3.js";
1616
import { mnemonicToSeedSync } from "bip39";
1717
import { sha512 } from "@noble/hashes/sha512";
18-
18+
import Bs58 from 'bs58'
1919
const PouchDB = require("pouchdb").default;
2020

2121
let isGetFaucetProcess = false;
@@ -43,12 +43,17 @@ async function deriveSolanaSeed(seed: any) {
4343

4444
const convertSecretKeyToPrivateKey = (secretKey: any) => {
4545
// Extract the first 32 bytes (private key)
46-
const privateKey = secretKey.slice(0, 32);
46+
// const privateKey = secretKey.slice(0, 32);
47+
// secretKey = private key (0,32) + public key (32, 64)
48+
// Phontom wallet import need BS58 inlcude private key (0,32) + public key (32, 64)
49+
50+
// const privateKeyHex = Buffer.from(privateKey).toString("hex");
51+
4752

48-
// Convert to a 64-character hex string (Ethereum format)
49-
const privateKeyHex = Buffer.from(privateKey).toString("hex");
53+
// return privateKeyHex;
5054

51-
return privateKeyHex;
55+
const privateKeyBs58 = Bs58.encode(secretKey)
56+
return privateKeyBs58
5257
};
5358

5459
const createOrGetWallet = async (secretPhrase: string | null) => {
@@ -99,6 +104,7 @@ const createOrGetWallet = async (secretPhrase: string | null) => {
99104

100105
const profile2: profile = {
101106
tokens: initProfileTokens(),
107+
102108
publicKeyArmor: secondaryWallet.publicKey.toString(),
103109
keyID: secondaryWallet.publicKey.toBase58(),
104110
isPrimary: true,
@@ -135,6 +141,7 @@ const createOrGetWallet = async (secretPhrase: string | null) => {
135141
secondaryWallet.secretKey
136142
);
137143

144+
138145
const key = await createGPGKey("", "", "");
139146

140147
const profile2: profile = {
@@ -157,9 +164,11 @@ const createOrGetWallet = async (secretPhrase: string | null) => {
157164
tmpData.profiles[1] = profile2;
158165
}
159166

160-
tmpData?.profiles.forEach(async (n: profile) => {
161-
n.keyID = n.keyID.toLocaleLowerCase();
162-
n.tokens.cCNTP.unlocked = false;
167+
tmpData?.profiles.forEach(async (n: profile, index: number) => {
168+
// Solana wallet don't need to toLocaleLowerCase
169+
if (index === 0) {
170+
n.keyID = n.keyID.toLocaleLowerCase();
171+
}
163172
});
164173

165174
setCoNET_Data(tmpData);

src/types.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@ interface CryptoAsset {
3535
}
3636

3737
interface conet_tokens {
38-
cCNTP: CryptoAsset;
39-
conet: CryptoAsset;
38+
conet: CryptoAsset
4039
conetDepin: CryptoAsset;
4140
conet_eth: CryptoAsset;
4241
eth: CryptoAsset;
42+
solana: CryptoAsset
43+
SP: CryptoAsset
4344
}
4445

4546
interface freePassport {

0 commit comments

Comments
 (0)