mirror of
https://github.com/pezkuwichain/pezkuwi-telegram-miniapp.git
synced 2026-06-19 22:41:05 +00:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ac4147304d | |||
| 6f1d293926 | |||
| 52b6344614 | |||
| de0f96a6a5 | |||
| e02ef74c58 | |||
| fc6be59519 | |||
| f5ad1cee29 | |||
| 39ff9e959f |
Generated
+1125
-452
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "pezkuwi-telegram-miniapp",
|
||||
"version": "1.0.230",
|
||||
"version": "1.0.233",
|
||||
"type": "module",
|
||||
"description": "Pezkuwichain Telegram Mini App - Forum, Announcements, Rewards",
|
||||
"author": "Pezkuwichain Team",
|
||||
|
||||
@@ -21,11 +21,14 @@ import {
|
||||
TrendingDown,
|
||||
Fuel,
|
||||
} from 'lucide-react';
|
||||
import type { ApiPromise } from '@pezkuwi/api';
|
||||
import { useWallet } from '@/contexts/WalletContext';
|
||||
import { useTelegram } from '@/hooks/useTelegram';
|
||||
import { useTranslation } from '@/i18n';
|
||||
import {
|
||||
subscribeToConnection,
|
||||
subscribeToAssetHubConnection,
|
||||
subscribeToPeopleConnection,
|
||||
getLastError,
|
||||
getAssetHubAPI,
|
||||
getPeopleAPI,
|
||||
@@ -76,6 +79,7 @@ interface TokenConfig {
|
||||
logo: string;
|
||||
isDefault: boolean;
|
||||
priority: number; // Lower = higher in list
|
||||
standard?: 'PEZ-20'; // fungible Asset Hub asset → PEZ-20 token standard
|
||||
}
|
||||
|
||||
const DEFAULT_TOKENS: TokenConfig[] = [
|
||||
@@ -98,6 +102,7 @@ const DEFAULT_TOKENS: TokenConfig[] = [
|
||||
logo: '/tokens/PEZ.png',
|
||||
isDefault: true,
|
||||
priority: 1,
|
||||
standard: 'PEZ-20',
|
||||
},
|
||||
{
|
||||
assetId: ASSET_IDS.WUSDT,
|
||||
@@ -108,6 +113,7 @@ const DEFAULT_TOKENS: TokenConfig[] = [
|
||||
logo: '/tokens/USDT.png',
|
||||
isDefault: true,
|
||||
priority: 2,
|
||||
standard: 'PEZ-20',
|
||||
},
|
||||
{
|
||||
assetId: ASSET_IDS.DOT,
|
||||
@@ -209,51 +215,68 @@ export function TokensCard({ onSendToken }: Props) {
|
||||
return () => unsubscribe();
|
||||
}, []);
|
||||
|
||||
// Fetch multi-chain HEZ balances (Asset Hub & People Chain)
|
||||
// Live multi-chain HEZ balances (Asset Hub & People Chain).
|
||||
// Uses real-time storage subscriptions and (re)subscribes the moment each
|
||||
// chain connects — so balances populate as soon as the chain is ready and
|
||||
// update instantly on any change (no 30s polling lag, no stuck "--").
|
||||
useEffect(() => {
|
||||
if (!address) return;
|
||||
let cancelled = false;
|
||||
let ahBalUnsub: (() => void) | null = null;
|
||||
let peopleBalUnsub: (() => void) | null = null;
|
||||
|
||||
const fetchMultiChainBalances = async () => {
|
||||
// Asset Hub HEZ balance
|
||||
const assetHubApi = getAssetHubAPI();
|
||||
if (assetHubApi) {
|
||||
try {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const accountInfo = (await (assetHubApi.query.system as any).account(address)) as {
|
||||
data: { free: { toString(): string } };
|
||||
};
|
||||
const free = accountInfo.data.free.toString();
|
||||
const balanceNum = Number(free) / 1e12;
|
||||
setAssetHubHezBalance(balanceNum.toFixed(4));
|
||||
} catch (err) {
|
||||
console.error('Error fetching Asset Hub HEZ balance:', err);
|
||||
setAssetHubHezBalance('0.0000');
|
||||
}
|
||||
}
|
||||
|
||||
// People Chain HEZ balance
|
||||
const peopleApi = getPeopleAPI();
|
||||
if (peopleApi) {
|
||||
try {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const accountInfo = (await (peopleApi.query.system as any).account(address)) as {
|
||||
data: { free: { toString(): string } };
|
||||
};
|
||||
const free = accountInfo.data.free.toString();
|
||||
const balanceNum = Number(free) / 1e12;
|
||||
setPeopleHezBalance(balanceNum.toFixed(4));
|
||||
} catch (err) {
|
||||
console.error('Error fetching People Chain HEZ balance:', err);
|
||||
setPeopleHezBalance('0.0000');
|
||||
}
|
||||
type AccountInfo = { data: { free: { toString(): string } } };
|
||||
const liveBalance = async (
|
||||
api: ApiPromise | null,
|
||||
setBalance: (v: string) => void,
|
||||
label: string
|
||||
) => {
|
||||
if (!api) return null;
|
||||
try {
|
||||
// callback form = live subscription, fires on every change
|
||||
const unsub = await api.query.system.account(address, (info: AccountInfo) => {
|
||||
const balanceNum = Number(info.data.free.toString()) / 1e12;
|
||||
setBalance(balanceNum.toFixed(4));
|
||||
});
|
||||
return unsub as unknown as () => void;
|
||||
} catch (err) {
|
||||
console.error(`Error subscribing to ${label} HEZ balance:`, err);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
fetchMultiChainBalances();
|
||||
// Refresh every 30 seconds
|
||||
const interval = setInterval(fetchMultiChainBalances, 30000);
|
||||
return () => clearInterval(interval);
|
||||
}, [address, rpcConnected]);
|
||||
const unsubAhConn = subscribeToAssetHubConnection(async (connected) => {
|
||||
if (ahBalUnsub) {
|
||||
ahBalUnsub();
|
||||
ahBalUnsub = null;
|
||||
}
|
||||
if (connected) {
|
||||
const u = await liveBalance(getAssetHubAPI(), setAssetHubHezBalance, 'Asset Hub');
|
||||
if (cancelled) u?.();
|
||||
else ahBalUnsub = u;
|
||||
}
|
||||
});
|
||||
|
||||
const unsubPeopleConn = subscribeToPeopleConnection(async (connected) => {
|
||||
if (peopleBalUnsub) {
|
||||
peopleBalUnsub();
|
||||
peopleBalUnsub = null;
|
||||
}
|
||||
if (connected) {
|
||||
const u = await liveBalance(getPeopleAPI(), setPeopleHezBalance, 'People Chain');
|
||||
if (cancelled) u?.();
|
||||
else peopleBalUnsub = u;
|
||||
}
|
||||
});
|
||||
|
||||
return () => {
|
||||
cancelled = true;
|
||||
if (ahBalUnsub) ahBalUnsub();
|
||||
if (peopleBalUnsub) peopleBalUnsub();
|
||||
unsubAhConn();
|
||||
unsubPeopleConn();
|
||||
};
|
||||
}, [address]);
|
||||
|
||||
// Initialize with default tokens immediately (no API required)
|
||||
const [tokens, setTokens] = useState<TokenBalance[]>(() =>
|
||||
@@ -838,6 +861,18 @@ export function TokensCard({ onSendToken }: Props) {
|
||||
<div>
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="font-semibold">{token.displaySymbol}</span>
|
||||
{token.standard === 'PEZ-20' && (
|
||||
<a
|
||||
href="https://docs.pezkuwichain.io/token-standards"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
title="PEZ-20 token standard on Pezkuwi Asset Hub"
|
||||
className="text-[10px] bg-blue-500/20 text-blue-300 px-1.5 py-0.5 rounded no-underline"
|
||||
>
|
||||
PEZ-20
|
||||
</a>
|
||||
)}
|
||||
{token.assetId <= -100 && (
|
||||
<span className="text-[10px] bg-purple-500/20 text-purple-400 px-1.5 py-0.5 rounded">
|
||||
LP
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": "1.0.230",
|
||||
"buildTime": "2026-02-27T23:33:39.279Z",
|
||||
"buildNumber": 1772235219280
|
||||
"version": "1.0.233",
|
||||
"buildTime": "2026-06-13T04:42:17.513Z",
|
||||
"buildNumber": 1781325737513
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user