mirror of
https://github.com/pezkuwichain/pezkuwi-telegram-miniapp.git
synced 2026-06-18 04:51:07 +00:00
fix: auto-sync wallet address to tg_users for deposit system
This commit is contained in:
@@ -16,6 +16,7 @@ import {
|
||||
AlertTriangle,
|
||||
} from 'lucide-react';
|
||||
import { useTelegram } from '@/hooks/useTelegram';
|
||||
import { useWallet } from '@/contexts/WalletContext';
|
||||
import { supabase } from '@/lib/supabase';
|
||||
|
||||
type Network = 'ton' | 'polkadot' | 'trc20';
|
||||
@@ -84,6 +85,7 @@ interface Props {
|
||||
|
||||
export function DepositUSDTModal({ isOpen, onClose }: Props) {
|
||||
const { hapticImpact, showAlert } = useTelegram();
|
||||
const { address: localWalletAddress } = useWallet();
|
||||
|
||||
const [selectedNetwork, setSelectedNetwork] = useState<Network>('ton');
|
||||
const [depositCode, setDepositCode] = useState<string>('');
|
||||
@@ -134,6 +136,13 @@ export function DepositUSDTModal({ isOpen, onClose }: Props) {
|
||||
} else {
|
||||
if (data?.code) setDepositCode(data.code);
|
||||
if (data?.trc20Address) setDepositAddress(data.trc20Address);
|
||||
|
||||
// If database doesn't have wallet but we have local wallet, sync it
|
||||
if (!data?.walletAddress && localWalletAddress) {
|
||||
supabase.functions.invoke('save-wallet-address', {
|
||||
body: { initData, walletAddress: localWalletAddress },
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Error fetching deposit info:', err);
|
||||
@@ -144,7 +153,7 @@ export function DepositUSDTModal({ isOpen, onClose }: Props) {
|
||||
};
|
||||
|
||||
fetchDepositInfo();
|
||||
}, [isOpen]);
|
||||
}, [isOpen, localWalletAddress]);
|
||||
|
||||
// Fetch deposits history
|
||||
useEffect(() => {
|
||||
|
||||
@@ -95,8 +95,9 @@ export async function syncWalletToSupabase(
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const client = supabase as any;
|
||||
|
||||
// UPDATE existing user's wallet_address (don't create new user)
|
||||
const { error } = await client
|
||||
// UPDATE existing user's wallet_address in both tables
|
||||
// Update 'users' table
|
||||
await client
|
||||
.from('users')
|
||||
.update({
|
||||
wallet_address: address,
|
||||
@@ -104,6 +105,15 @@ export async function syncWalletToSupabase(
|
||||
})
|
||||
.eq('telegram_id', telegramId);
|
||||
|
||||
// Also update 'tg_users' table (used by deposit system)
|
||||
const { error } = await client
|
||||
.from('tg_users')
|
||||
.update({
|
||||
wallet_address: address,
|
||||
updated_at: new Date().toISOString(),
|
||||
})
|
||||
.eq('telegram_id', telegramId);
|
||||
|
||||
if (error) {
|
||||
console.error('Wallet sync error:', error);
|
||||
throw new Error('Wallet adresa DB-ê re senkronîze nebû');
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": "1.0.175",
|
||||
"buildTime": "2026-02-08T00:56:36.820Z",
|
||||
"buildNumber": 1770512196820
|
||||
"version": "1.0.177",
|
||||
"buildTime": "2026-02-08T01:24:06.896Z",
|
||||
"buildNumber": 1770513846897
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user