Merge remote-tracking branch 'origin/dev'
This commit is contained in:
commit
45f992c386
Binary file not shown.
Binary file not shown.
|
|
@ -3,6 +3,7 @@
|
|||
import Footer from "@/components/Footer";
|
||||
import Header from "@/components/Header";
|
||||
import HeroSection from "@/components/HeroSection";
|
||||
import Leaderboard from "@/components/Leaderboard";
|
||||
// import Leaderboard from "@/components/Leaderboard";
|
||||
import { PrivyProvider } from "@privy-io/react-auth";
|
||||
import { toSolanaWalletConnectors } from "@privy-io/react-auth/solana";
|
||||
|
|
@ -37,7 +38,7 @@ export default function Home() {
|
|||
<Toaster position="top-right" richColors />
|
||||
<Header />
|
||||
<HeroSection />
|
||||
{/* <Leaderboard /> */}
|
||||
<Leaderboard />
|
||||
<Footer />
|
||||
</>
|
||||
</PrivyProvider>
|
||||
|
|
|
|||
|
|
@ -22,13 +22,15 @@ export function GameSelection({ games, selectedGame, onSelect }: GameSelectionPr
|
|||
}`}
|
||||
onClick={() => game.isAvailable && onSelect(game)}
|
||||
>
|
||||
<Image
|
||||
src={game.thumbnail}
|
||||
alt={game.name}
|
||||
width={100}
|
||||
height={100}
|
||||
className="mb-2 rounded-md"
|
||||
/>
|
||||
<div className="flex justify-center">
|
||||
<Image
|
||||
src={game.thumbnail}
|
||||
alt={game.name}
|
||||
width={100}
|
||||
height={100}
|
||||
className="mb-2 rounded-md"
|
||||
/>
|
||||
</div>
|
||||
<h3 className="text-center text-sm">{game.name}</h3>
|
||||
{!game.isAvailable && (
|
||||
<p className="text-center text-xs text-gray-500 mt-1">Coming Soon</p>
|
||||
|
|
|
|||
|
|
@ -71,11 +71,12 @@ export default function Leaderboard() {
|
|||
<h3 className="text-white font-semibold">
|
||||
{entry.user_data?.username || "Anonymous"}
|
||||
</h3>
|
||||
<p className="text-sm text-gray-400">{entry.user_data?.bio || "No bio"}</p>
|
||||
<p className="text-sm text-gray-400 hidden md:block">{entry.user_data?.bio || "No bio"}</p>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="flex flex-col items-center">
|
||||
<span className="text-[rgb(248,144,22)] font-bold">{entry.wins}</span>
|
||||
<span className="text-gray-400">wins</span>
|
||||
<span className="text-gray-400 text-xs md:hidden">wins</span>
|
||||
<span className="text-gray-400 hidden md:block">wins</span>
|
||||
</div>
|
||||
<Image
|
||||
src={profileUrl}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ import { games } from "@/data/games";
|
|||
import { WAGER_PRIZE_MULT } from "@/shared/constants";
|
||||
import { EXPLORER_ADDRESS_TEMPLATE } from "@/data/shared";
|
||||
|
||||
const ENABLE_REFERRAL_SYSTEM = false; // Toggle for referral system visibility
|
||||
|
||||
interface GameHistory {
|
||||
ended_time: string;
|
||||
address: string;
|
||||
|
|
@ -38,6 +40,27 @@ interface Opponent {
|
|||
x_profile_url: string;
|
||||
}
|
||||
|
||||
interface Referee {
|
||||
ref_id: string;
|
||||
id: string;
|
||||
username: string;
|
||||
bio: string;
|
||||
x_profile_url: string;
|
||||
referred_id: string;
|
||||
profilePicture?: string;
|
||||
joinedAt?: string;
|
||||
earnings?: number;
|
||||
}
|
||||
|
||||
interface ApiReferee {
|
||||
ref_id: string;
|
||||
id: string;
|
||||
username: string;
|
||||
bio: string;
|
||||
x_profile_url: string;
|
||||
referred_id: string;
|
||||
}
|
||||
|
||||
const GameHistoryItem = ({ game, user, gameImages, defaultPFP, failedImages, setFailedImages, handleViewTxClick }: {
|
||||
game: GameHistory,
|
||||
user: User,
|
||||
|
|
@ -166,11 +189,17 @@ export default function PrivyButton() {
|
|||
const defaultPFP = '/duelfiassets/PFP (1).png';
|
||||
|
||||
const [username, setUsername] = useState("Tester");
|
||||
const [refId, setRefId] = useState(0);
|
||||
const [bio, setBio] = useState("");
|
||||
const [avatar, setAvatar] = useState<string | null>(null);
|
||||
|
||||
const [isUsernameClaimModalOpen, setIsUsernameClaimModalOpen] = useState(false);
|
||||
const [newUsername, setNewUsername] = useState("");
|
||||
const [referralId, setReferralId] = useState("");
|
||||
|
||||
const [isReferreesModalOpen, setIsReferreesModalOpen] = useState(false);
|
||||
const [referrees, setReferrees] = useState<Referee[]>([]);
|
||||
const [referralStats, setReferralStats] = useState({ earnings: 0, count: 0 });
|
||||
|
||||
const modalRef = useRef<HTMLDivElement>(null);
|
||||
const updateSolWallet = () => {
|
||||
|
|
@ -239,6 +268,7 @@ export default function PrivyButton() {
|
|||
} else {
|
||||
setUsername(data.username || "Tester");
|
||||
setBio(data.bio || "");
|
||||
setRefId(data.ref_id || 0);
|
||||
|
||||
// Check if the user has a profile picture URL and update in database
|
||||
const customProfileUrl = `${API_URL}profile_pics/${user.id}.jpg`;
|
||||
|
|
@ -341,16 +371,31 @@ export default function PrivyButton() {
|
|||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
// Check for referral ID in URL when modal opens
|
||||
if (isUsernameClaimModalOpen) {
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const refId = urlParams.get('ref');
|
||||
if (refId) {
|
||||
setReferralId(refId);
|
||||
}
|
||||
}
|
||||
}, [isUsernameClaimModalOpen]);
|
||||
|
||||
const handleUsernameClaim = async () => {
|
||||
if (newUsername.trim()) {
|
||||
const apiUrl = `${API_URL}register.php?id=${user?.id}&username=${newUsername}`;
|
||||
try {
|
||||
const response = await fetch(apiUrl);
|
||||
const data = await response.text();
|
||||
if (data == "0") {
|
||||
// First register the user
|
||||
const registerUrl = `${API_URL}register.php?id=${user?.id}&username=${newUsername}&ref_id=${referralId}`;
|
||||
const registerResponse = await fetch(registerUrl);
|
||||
const registerData = await registerResponse.text();
|
||||
|
||||
if (registerData == "0") {
|
||||
|
||||
|
||||
toast.success("Username claimed successfully!");
|
||||
setIsUsernameClaimModalOpen(false);
|
||||
fetchUserData(); // Refresh user data to get the new username
|
||||
} else {
|
||||
toast.error("Failed to claim username.");
|
||||
}
|
||||
|
|
@ -416,6 +461,7 @@ export default function PrivyButton() {
|
|||
);
|
||||
|
||||
setGameImages(gameDataWithImages);
|
||||
fetchReferralData();
|
||||
} catch (err) {
|
||||
console.error("Error fetching game history", err);
|
||||
} finally {
|
||||
|
|
@ -431,6 +477,32 @@ export default function PrivyButton() {
|
|||
window.open(`${EXPLORER_ADDRESS_TEMPLATE.replace("{address}",address)}`, "_blank");
|
||||
};
|
||||
|
||||
const fetchReferralData = async () => {
|
||||
if (!refId) return;
|
||||
|
||||
try {
|
||||
const response = await axios.get<ApiReferee[]>(`${API_URL}get_users_by_referral.php?id=${refId}`);
|
||||
const referreesData = response.data || [];
|
||||
|
||||
// Transform the data to match our Referee interface
|
||||
const transformedReferrees = referreesData.map((ref: ApiReferee) => ({
|
||||
...ref,
|
||||
profilePicture: ref.x_profile_url,
|
||||
joinedAt: new Date().toISOString(), // Since join date isn't provided in API
|
||||
earnings: 0.01 // Each referral gives 0.01 SOL
|
||||
}));
|
||||
|
||||
setReferrees(transformedReferrees);
|
||||
setReferralStats({
|
||||
earnings: transformedReferrees.length * 0.01, // 0.01 SOL per referral
|
||||
count: transformedReferrees.length
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch referral data:', error);
|
||||
toast.error('Failed to load referral data');
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
{user ? (
|
||||
|
|
@ -639,6 +711,69 @@ export default function PrivyButton() {
|
|||
{/* Divider */}
|
||||
<hr className="border-gray-600" />
|
||||
|
||||
{/* Referral Section */}
|
||||
{ENABLE_REFERRAL_SYSTEM && (
|
||||
<div>
|
||||
<h3 className="text-xl font-bold mb-4">Referral Program</h3>
|
||||
<div className="bg-gray-800 p-4 rounded-lg">
|
||||
<div className="flex items-center justify-between mb-4">
|
||||
<div className="flex items-center gap-2">
|
||||
<p className="text-gray-400 text-sm">Your Referral ID:</p>
|
||||
<p className="font-mono text-sm">{user?.id?.slice(0, 8)}</p>
|
||||
<button
|
||||
onClick={() => {
|
||||
navigator.clipboard.writeText(user?.id || '');
|
||||
toast.success('Referral ID copied!');
|
||||
}}
|
||||
className="text-gray-400 hover:text-white transition p-1"
|
||||
>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" className="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M8 5H6a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2v-1M8 5a2 2 0 002 2h2a2 2 0 002-2M8 5a2 2 0 012-2h2a2 2 0 012 2m0 0h2a2 2 0 012 2v3m2 4H10m0 0l3-3m-3 3l3 3" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
<button
|
||||
onClick={() => {
|
||||
const referralLink = `${window.location.origin}?ref=${user?.id}`;
|
||||
navigator.clipboard.writeText(referralLink);
|
||||
toast.success('Referral link copied!');
|
||||
}}
|
||||
className="bg-[rgb(248,144,22)] hover:bg-[rgb(248,200,100)] text-black px-4 py-2 rounded-md text-sm font-semibold flex items-center gap-2"
|
||||
>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" className="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M8.684 13.342C8.886 12.938 9 12.482 9 12c0-.482-.114-.938-.316-1.342m0 2.684a3 3 0 110-2.684m0 2.684l6.632 3.316m-6.632-6l6.632-3.316m0 0a3 3 0 105.367-2.684 3 3 0 00-5.367 2.684zm0 9.316a3 3 0 105.368 2.684 3 3 0 00-5.368-2.684z" />
|
||||
</svg>
|
||||
Share
|
||||
</button>
|
||||
</div>
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-4">
|
||||
<div>
|
||||
<p className="text-gray-400 text-xs">Referral Earnings</p>
|
||||
<p className="text-lg font-semibold">{referralStats.earnings.toFixed(2)} SOL</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-gray-400 text-xs">Total Referrals</p>
|
||||
<p className="text-lg font-semibold">{referralStats.count}</p>
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
onClick={() => setIsReferreesModalOpen(true)}
|
||||
className="bg-gray-700 hover:bg-gray-600 text-white px-4 py-2 rounded-md text-sm font-semibold flex items-center gap-2"
|
||||
>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" className="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z" />
|
||||
</svg>
|
||||
View Referrees
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Divider */}
|
||||
<hr className="border-gray-600" />
|
||||
|
||||
{/* Game History Section */}
|
||||
<div>
|
||||
<h3 className="text-xl font-bold mb-4">Game History</h3>
|
||||
|
|
@ -684,18 +819,78 @@ export default function PrivyButton() {
|
|||
</div>
|
||||
)}
|
||||
|
||||
{/* Referrees Modal */}
|
||||
{ENABLE_REFERRAL_SYSTEM && isReferreesModalOpen && (
|
||||
<div className="fixed inset-0 bg-black/70 flex justify-center items-center z-50">
|
||||
<div className="bg-[rgb(30,30,30)] text-white w-full max-w-lg p-6 rounded-2xl shadow-lg space-y-6">
|
||||
<div className="flex justify-between items-center">
|
||||
<h2 className="text-2xl font-bold">Your Referrees</h2>
|
||||
<button
|
||||
onClick={() => setIsReferreesModalOpen(false)}
|
||||
className="text-gray-400 hover:text-white transition duration-300 hover:scale-105"
|
||||
>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" className="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
<div className="max-h-96 overflow-y-auto space-y-4">
|
||||
{referrees.length === 0 ? (
|
||||
<p className="text-gray-500 text-center py-4">No referrees yet.</p>
|
||||
) : (
|
||||
referrees.map((referee, index) => (
|
||||
<div key={index} className="flex items-center justify-between bg-gray-800 p-3 rounded-lg">
|
||||
<div className="flex items-center gap-3">
|
||||
<Image
|
||||
src={referee.profilePicture || defaultPFP}
|
||||
alt="Profile"
|
||||
width={40}
|
||||
height={40}
|
||||
className="rounded-full border border-gray-700 object-cover"
|
||||
/>
|
||||
<div>
|
||||
<p className="font-semibold">{referee.username}</p>
|
||||
<p className="text-sm text-gray-400">Joined {referee.joinedAt ? new Date(referee.joinedAt).toLocaleDateString() : 'Recently'}</p>
|
||||
</div>
|
||||
</div>
|
||||
<p className="text-sm text-gray-400">{referee.earnings} SOL earned</p>
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Username Claim Modal */}
|
||||
{isUsernameClaimModalOpen && (
|
||||
<div className="fixed inset-0 bg-black/70 flex justify-center items-center z-50">
|
||||
<div className="bg-[rgb(30,30,30)] text-white w-full max-w-lg p-6 rounded-2xl shadow-lg space-y-6">
|
||||
<h2 className="text-2xl font-bold">Claim Your Username</h2>
|
||||
<input
|
||||
type="text"
|
||||
value={newUsername}
|
||||
onChange={(e) => setNewUsername(e.target.value)}
|
||||
className="w-full bg-[rgb(10,10,10)] text-white p-2 rounded-md"
|
||||
placeholder="Enter your new username"
|
||||
/>
|
||||
<div className="space-y-4">
|
||||
<div>
|
||||
<label className="block text-sm text-gray-400 mb-1">Username</label>
|
||||
<input
|
||||
type="text"
|
||||
value={newUsername}
|
||||
onChange={(e) => setNewUsername(e.target.value)}
|
||||
className="w-full bg-[rgb(10,10,10)] text-white p-2 rounded-md"
|
||||
placeholder="Enter your new username"
|
||||
/>
|
||||
</div>
|
||||
{ENABLE_REFERRAL_SYSTEM && (
|
||||
<div>
|
||||
<label className="block text-sm text-gray-400 mb-1">Referral ID (Optional)</label>
|
||||
<input
|
||||
type="text"
|
||||
value={referralId}
|
||||
onChange={(e) => setReferralId(e.target.value)}
|
||||
className="w-full bg-[rgb(10,10,10)] text-white p-2 rounded-md"
|
||||
placeholder="Enter referral ID if you have one"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<button
|
||||
onClick={handleUsernameClaim}
|
||||
className="w-full bg-[rgb(248,144,22)] hover:bg-orange-400 text-white px-4 py-2 rounded-md transition duration-500 hover:scale-105"
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { API_URL } from "@/data/shared";
|
||||
import { API_URL, CLUSTER_URL } from "@/data/shared";
|
||||
import { clusterApiUrl } from "@solana/web3.js";
|
||||
|
||||
export async function fetchUserById(id: string) {
|
||||
const url = `${API_URL}get_user_by_id.php?id=${id}`;
|
||||
|
|
@ -9,7 +10,8 @@ export async function fetchUserById(id: string) {
|
|||
|
||||
export async function showNewGameNotification(username:string, game:string, wager:string){
|
||||
try{
|
||||
await fetch(`${API_URL}send_telegram_notification.php?username=${username}&wager=${wager}&game=${game}`)
|
||||
const isDevnet = CLUSTER_URL === clusterApiUrl("devnet");
|
||||
await fetch(`${API_URL}send_telegram_notification.php?username=${username}&wager=${wager}&game=${game}&devnet=${isDevnet ? "1" : "0"}`)
|
||||
}catch(error){
|
||||
console.error("Error showing new game notification:", error);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user