mirror of
https://github.com/pezkuwichain/pwap.git
synced 2026-04-22 05:37:56 +00:00
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:
Binary file not shown.
|
After Width: | Height: | Size: 286 KiB |
+36
-8
@@ -80,37 +80,65 @@ export interface PoolCreationParams {
|
|||||||
// Native token ID constant (relay chain HEZ)
|
// Native token ID constant (relay chain HEZ)
|
||||||
export const NATIVE_TOKEN_ID = -1;
|
export const NATIVE_TOKEN_ID = -1;
|
||||||
|
|
||||||
// Known tokens on testnet
|
// Known tokens on testnet (assets pallet)
|
||||||
export const KNOWN_TOKENS: Record<number, TokenInfo> = {
|
export const KNOWN_TOKENS: Record<number, TokenInfo> = {
|
||||||
[-1]: {
|
[-1]: {
|
||||||
id: -1,
|
id: -1,
|
||||||
symbol: 'HEZ',
|
symbol: 'HEZ',
|
||||||
name: 'Native HEZ',
|
name: 'Native HEZ',
|
||||||
decimals: 12,
|
decimals: 12,
|
||||||
},
|
logo: '/shared/images/hez_token_512.png',
|
||||||
0: {
|
|
||||||
id: 0,
|
|
||||||
symbol: 'wHEZ',
|
|
||||||
name: 'Wrapped HEZ',
|
|
||||||
decimals: 12,
|
|
||||||
},
|
},
|
||||||
1: {
|
1: {
|
||||||
id: 1,
|
id: 1,
|
||||||
symbol: 'PEZ',
|
symbol: 'PEZ',
|
||||||
name: 'Pezkuwi Token',
|
name: 'Pezkuwi Token',
|
||||||
decimals: 12,
|
decimals: 12,
|
||||||
|
logo: '/shared/images/pez_token_512.png',
|
||||||
},
|
},
|
||||||
2: {
|
2: {
|
||||||
id: 2,
|
id: 2,
|
||||||
symbol: 'wHEZ',
|
symbol: 'wHEZ',
|
||||||
name: 'Wrapped HEZ (Asset Hub)',
|
name: 'Wrapped HEZ',
|
||||||
decimals: 12,
|
decimals: 12,
|
||||||
|
logo: '/shared/images/hez_token_512.png',
|
||||||
},
|
},
|
||||||
1000: {
|
1000: {
|
||||||
id: 1000,
|
id: 1000,
|
||||||
symbol: 'wUSDT',
|
symbol: 'wUSDT',
|
||||||
name: 'Wrapped USDT',
|
name: 'Wrapped USDT',
|
||||||
decimals: 6,
|
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],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,10 @@ interface TokenBalances {
|
|||||||
HEZ: string;
|
HEZ: string;
|
||||||
PEZ: string;
|
PEZ: string;
|
||||||
wHEZ: 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 {
|
interface WalletContextType {
|
||||||
@@ -48,7 +51,14 @@ export const WalletProvider: React.FC<{ children: React.ReactNode }> = ({ childr
|
|||||||
});
|
});
|
||||||
|
|
||||||
const [balance, setBalance] = useState<string>('0');
|
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 [error, setError] = useState<string | null>(null);
|
||||||
const [signer, setSigner] = useState<Signer | 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);
|
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({
|
setBalances({
|
||||||
HEZ: hezBalance,
|
HEZ: hezBalance,
|
||||||
PEZ: pezBalance,
|
PEZ: pezBalance,
|
||||||
wHEZ: whezBalance,
|
wHEZ: whezBalance,
|
||||||
USDT: wusdtBalance,
|
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) {
|
} catch (err) {
|
||||||
if (import.meta.env.DEV) console.error('Failed to fetch balances:', err);
|
if (import.meta.env.DEV) console.error('Failed to fetch balances:', err);
|
||||||
setError('Failed to fetch balances');
|
setError('Failed to fetch balances');
|
||||||
|
|||||||
Reference in New Issue
Block a user