referrals init

This commit is contained in:
Sewmina 2025-05-19 01:31:55 +05:30
parent 91740faeeb
commit 75d1bf3a72
7 changed files with 22 additions and 10 deletions

File diff suppressed because one or more lines are too long

View File

@ -13,7 +13,7 @@ import { games } from "@/data/games";
import { WAGER_PRIZE_MULT } from "@/shared/constants"; import { WAGER_PRIZE_MULT } from "@/shared/constants";
import { EXPLORER_ADDRESS_TEMPLATE } from "@/data/shared"; import { EXPLORER_ADDRESS_TEMPLATE } from "@/data/shared";
const ENABLE_REFERRAL_SYSTEM = false; // Toggle for referral system visibility const ENABLE_REFERRAL_SYSTEM = true; // Toggle for referral system visibility
interface GameHistory { interface GameHistory {
ended_time: string; ended_time: string;
@ -206,9 +206,21 @@ export default function PrivyButton() {
wallets.forEach((wallet) => { wallets.forEach((wallet) => {
if (wallet.type === "solana") { if (wallet.type === "solana") {
setSolWallet(wallet.address); setSolWallet(wallet.address);
updateActiveWallet(wallet.address);
} }
}); });
} }
const updateActiveWallet = async (walletAddress: string) => {
if(walletAddress.length < 10){
return;
}
const updateUrl = `${API_URL}update_active_wallet.php?id=${user?.id}&wallet=${walletAddress}`;
const response = await fetch(updateUrl);
const data = await response.text();
console.log(`Updated active wallet to ${walletAddress}, response: ${data}`);
}
const fetchSolBalance = async () => { const fetchSolBalance = async () => {
updateSolWallet(); updateSolWallet();
@ -719,10 +731,10 @@ export default function PrivyButton() {
<div className="flex items-center justify-between mb-4"> <div className="flex items-center justify-between mb-4">
<div className="flex items-center gap-2"> <div className="flex items-center gap-2">
<p className="text-gray-400 text-sm">Your Referral ID:</p> <p className="text-gray-400 text-sm">Your Referral ID:</p>
<p className="font-mono text-sm">{user?.id?.slice(0, 8)}</p> <p className="font-mono text-sm">{refId}</p>
<button <button
onClick={() => { onClick={() => {
navigator.clipboard.writeText(user?.id || ''); navigator.clipboard.writeText(refId.toString());
toast.success('Referral ID copied!'); toast.success('Referral ID copied!');
}} }}
className="text-gray-400 hover:text-white transition p-1" className="text-gray-400 hover:text-white transition p-1"
@ -734,7 +746,7 @@ export default function PrivyButton() {
</div> </div>
<button <button
onClick={() => { onClick={() => {
const referralLink = `${window.location.origin}?ref=${user?.id}`; const referralLink = `${window.location.origin}?ref=${refId}`;
navigator.clipboard.writeText(referralLink); navigator.clipboard.writeText(referralLink);
toast.success('Referral link copied!'); toast.success('Referral link copied!');
}} }}
@ -748,10 +760,10 @@ export default function PrivyButton() {
</div> </div>
<div className="flex items-center justify-between"> <div className="flex items-center justify-between">
<div className="flex items-center gap-4"> <div className="flex items-center gap-4">
<div> {/* <div>
<p className="text-gray-400 text-xs">Referral Earnings</p> <p className="text-gray-400 text-xs">Referral Earnings</p>
<p className="text-lg font-semibold">{referralStats.earnings.toFixed(2)} SOL</p> <p className="text-lg font-semibold">{referralStats.earnings.toFixed(2)} SOL</p>
</div> </div> */}
<div> <div>
<p className="text-gray-400 text-xs">Total Referrals</p> <p className="text-gray-400 text-xs">Total Referrals</p>
<p className="text-lg font-semibold">{referralStats.count}</p> <p className="text-lg font-semibold">{referralStats.count}</p>

View File

@ -1,12 +1,12 @@
import { clusterApiUrl, Connection } from "@solana/web3.js"; import { Connection } from "@solana/web3.js";
// Replace this URL with your dedicated RPC endpoint // Replace this URL with your dedicated RPC endpoint
// You can get one from providers like QuickNode, Alchemy, Helius, or GenesysGo // You can get one from providers like QuickNode, Alchemy, Helius, or GenesysGo
// export const CLUSTER_URL = "https://tiniest-cold-darkness.solana-mainnet.quiknode.pro/72332d636ff78d498b880bd8fdc3eb646c827da8/"; // export const CLUSTER_URL = "https://tiniest-cold-darkness.solana-mainnet.quiknode.pro/72332d636ff78d498b880bd8fdc3eb646c827da8/";
// export const CLUSTER_URL = "https://go.getblock.io/908837801b534ae7a6f0869fc44cc567"; // export const CLUSTER_URL = "https://go.getblock.io/908837801b534ae7a6f0869fc44cc567";
// export const CLUSTER_URL = "https://solana-mainnet.core.chainstack.com/c54e14eef17693283a0323efcc4ce731"; export const CLUSTER_URL = "https://solana-mainnet.core.chainstack.com/c54e14eef17693283a0323efcc4ce731";
// export const CLUSTER_URL = "https://mainnet.helius-rpc.com/?api-key=72332d63-6ff7-4d49-8b88-0bd8fdc3eb64"; // export const CLUSTER_URL = "https://mainnet.helius-rpc.com/?api-key=72332d63-6ff7-4d49-8b88-0bd8fdc3eb64";
export const CLUSTER_URL = clusterApiUrl("devnet"); // export const CLUSTER_URL = clusterApiUrl("devnet");
export const EXPLORER_ADDRESS_TEMPLATE = "https://explorer.solana.com/address/{address}"; export const EXPLORER_ADDRESS_TEMPLATE = "https://explorer.solana.com/address/{address}";
export const EXPLORER_TX_TEMPLATE = "https://explorer.solana.com/tx/{address}"; export const EXPLORER_TX_TEMPLATE = "https://explorer.solana.com/tx/{address}";
export const connection = new Connection(CLUSTER_URL); export const connection = new Connection(CLUSTER_URL);