feat: add LP token support and display in wallet

- Add LP_TOKENS definition in shared/types/dex.ts
- Fetch LP token balances from poolAssets pallet
- Add HEZ-PEZ-LP and HEZ-USDT-LP to TokenBalances
- Add lp_token_512.png logo
This commit is contained in:
2026-02-05 00:35:46 +03:00
parent 7e3b2b6d86
commit 51904c206c
3 changed files with 79 additions and 11 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 286 KiB

+36 -8
View File
@@ -80,37 +80,65 @@ export interface PoolCreationParams {
// Native token ID constant (relay chain HEZ)
export const NATIVE_TOKEN_ID = -1;
// Known tokens on testnet
// Known tokens on testnet (assets pallet)
export const KNOWN_TOKENS: Record<number, TokenInfo> = {
[-1]: {
id: -1,
symbol: 'HEZ',
name: 'Native HEZ',
decimals: 12,
},
0: {
id: 0,
symbol: 'wHEZ',
name: 'Wrapped HEZ',
decimals: 12,
logo: '/shared/images/hez_token_512.png',
},
1: {
id: 1,
symbol: 'PEZ',
name: 'Pezkuwi Token',
decimals: 12,
logo: '/shared/images/pez_token_512.png',
},
2: {
id: 2,
symbol: 'wHEZ',
name: 'Wrapped HEZ (Asset Hub)',
name: 'Wrapped HEZ',
decimals: 12,
logo: '/shared/images/hez_token_512.png',
},
1000: {
id: 1000,
symbol: 'wUSDT',
name: 'Wrapped USDT',
decimals: 6,
logo: '/shared/images/USDT(hez)logo.png',
},
};
// LP Token info (poolAssets pallet - separate from assets pallet)
export interface LPTokenInfo {
id: number;
symbol: string;
name: string;
decimals: number;
logo: string;
poolPair: [number, number]; // [asset1, asset2]
}
// Known LP tokens (from poolAssets pallet)
export const LP_TOKENS: Record<number, LPTokenInfo> = {
0: {
id: 0,
symbol: 'HEZ-PEZ LP',
name: 'HEZ-PEZ Liquidity',
decimals: 12,
logo: '/shared/images/lp_token_512.png',
poolPair: [NATIVE_TOKEN_ID, 1],
},
1: {
id: 1,
symbol: 'HEZ-USDT LP',
name: 'HEZ-USDT Liquidity',
decimals: 12,
logo: '/shared/images/lp_token_512.png',
poolPair: [NATIVE_TOKEN_ID, 1000],
},
};
+43 -3
View File
@@ -16,7 +16,10 @@ interface TokenBalances {
HEZ: string;
PEZ: string;
wHEZ: string;
USDT: string; // User-facing key for wUSDT (backend uses wUSDT asset ID 2)
USDT: string; // User-facing key for wUSDT (asset ID 1000)
// LP Tokens (from poolAssets pallet)
'HEZ-PEZ-LP': string;
'HEZ-USDT-LP': string;
}
interface WalletContextType {
@@ -48,7 +51,14 @@ export const WalletProvider: React.FC<{ children: React.ReactNode }> = ({ childr
});
const [balance, setBalance] = useState<string>('0');
const [balances, setBalances] = useState<TokenBalances>({ HEZ: '0', PEZ: '0', wHEZ: '0', USDT: '0' });
const [balances, setBalances] = useState<TokenBalances>({
HEZ: '0',
PEZ: '0',
wHEZ: '0',
USDT: '0',
'HEZ-PEZ-LP': '0',
'HEZ-USDT-LP': '0',
});
const [error, setError] = useState<string | null>(null);
const [signer, setSigner] = useState<Signer | null>(null);
@@ -132,14 +142,44 @@ export const WalletProvider: React.FC<{ children: React.ReactNode }> = ({ childr
if (import.meta.env.DEV) console.error('❌ Failed to fetch wUSDT balance:', err);
}
// Fetch LP Token balances from poolAssets pallet
let hezPezLpBalance = '0';
let hezUsdtLpBalance = '0';
try {
// HEZ-PEZ LP Token (ID: 0)
const hezPezLp = await assetApi.query.poolAssets.account(0, address);
if (hezPezLp.isSome) {
hezPezLpBalance = formatBalance(hezPezLp.unwrap().balance.toString());
if (import.meta.env.DEV) console.log('✅ HEZ-PEZ LP balance:', hezPezLpBalance);
}
// HEZ-USDT LP Token (ID: 1)
const hezUsdtLp = await assetApi.query.poolAssets.account(1, address);
if (hezUsdtLp.isSome) {
hezUsdtLpBalance = formatBalance(hezUsdtLp.unwrap().balance.toString());
if (import.meta.env.DEV) console.log('✅ HEZ-USDT LP balance:', hezUsdtLpBalance);
}
} catch (err) {
if (import.meta.env.DEV) console.error('❌ Failed to fetch LP balances:', err);
}
setBalances({
HEZ: hezBalance,
PEZ: pezBalance,
wHEZ: whezBalance,
USDT: wusdtBalance,
'HEZ-PEZ-LP': hezPezLpBalance,
'HEZ-USDT-LP': hezUsdtLpBalance,
});
if (import.meta.env.DEV) console.log('✅ Balances updated:', { HEZ: hezBalance, PEZ: pezBalance, wHEZ: whezBalance, wUSDT: wusdtBalance });
if (import.meta.env.DEV) console.log('✅ Balances updated:', {
HEZ: hezBalance,
PEZ: pezBalance,
wHEZ: whezBalance,
USDT: wusdtBalance,
'HEZ-PEZ-LP': hezPezLpBalance,
'HEZ-USDT-LP': hezUsdtLpBalance,
});
} catch (err) {
if (import.meta.env.DEV) console.error('Failed to fetch balances:', err);
setError('Failed to fetch balances');