feat: write p2p_user_id to tg_users on Telegram wallet link

TelegramConnect: query tg_users instead of users, resolve visa UUID
from p2p_visa table and store as p2p_user_id for cross-platform P2P.

P2PIdentityContext: when citizen resolves their UUID, backfill
tg_users.p2p_user_id if their wallet is linked to a Telegram account.
This commit is contained in:
2026-04-27 13:31:22 +03:00
parent 09da6e80b7
commit 86ff43e206
2 changed files with 42 additions and 5 deletions
+15
View File
@@ -54,6 +54,21 @@ export function P2PIdentityProvider({ children }: { children: ReactNode }) {
const uuid = await identityToUUID(fullCitizenNumber);
setUserId(uuid);
setVisaNumber(null);
// If this wallet is linked to a Telegram account and p2p_user_id not set yet,
// backfill it so mini app users see the same P2P identity
if (walletAddress) {
supabase
.from('tg_users')
.select('id, p2p_user_id')
.eq('wallet_address', walletAddress)
.maybeSingle()
.then(({ data: tgUser }) => {
if (tgUser && !tgUser.p2p_user_id) {
supabase.from('tg_users').update({ p2p_user_id: uuid }).eq('id', tgUser.id);
}
});
}
} else if (walletAddress) {
// Non-citizen: check for existing visa
const { data: visa } = await supabase