funds123/ethereum_wallet_view_safe_app

ethereum_wallet_view_safe_app

Open

#1 opened on Jun 20, 2025

View on GitHub
 (1 comment) (0 reactions) (1 assignee)Python (1 fork)auto 404
documentationenhancementgood first issue

Repository metrics

Stars
 (1 star)
PR merge metrics
 (PR metrics pending)

Description

import shutil from pathlib import Path

Define the project root and zip destination

project_root = Path("/mnt/data/ethereum_wallet_view_safe_app") zip_path = "/mnt/data/ethereum_wallet_view_safe_app.zip"

// src/hooks/useTokenBalances.ts

import { useEffect, useState } from 'react'; import { ethers } from 'ethers'; import { useChain } from '@/hooks/useChain'; import ERC20_ABI from '@/abis/erc20.json';

const TOKENS = [ { symbol: 'ETH', address: ethers.ZeroAddress, decimals: 18 }, { symbol: 'USDC', address: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', decimals: 6 }, { symbol: 'DAI', address: '0x6B175474E89094C44Da98b954EedeAC495271d0F', decimals: 18 }, { symbol: 'WBTC', address: '0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599', decimals: 8 }, { symbol: 'USDT', address: '0xdAC17F958D2ee523a2206206994597C13D831ec7', decimals: 6 }, ];

export function useTokenBalances(account?: string) { const { rpcUrl, loading: chainLoading } = useChain(); const [balances, setBalances] = useState<Record<string, string>>({}); const [loading, setLoading] = useState(true);

useEffect(() => { if (!account || chainLoading) return;

const fetchBalances = async () => { console.log('Fetching token balances...'); console.log('Account:', account); console.log('RPC URL:', rpcUrl);

const provider = new ethers.JsonRpcProvider(rpcUrl); const result: Record<string, string> = {};

for (const token of TOKENS) { try { console.log(Fetching balance for ${token.symbol} at ${token.address});

  if (token.address === ethers.ZeroAddress) {
    const balance = await provider.getBalance(account);
    result[token.symbol] = ethers.formatUnits(balance, token.decimals);
  } else {
    const tokenContract = new ethers.Contract(token.address, ERC20_ABI, provider);
    const balance = await tokenContract.balanceOf(account);
    result[token.symbol] = ethers.formatUnits(balance, token.decimals);
  }

  console.log(`${token.symbol} balance:`, result[token.symbol]);
} catch (error) {
  console.error(`Error fetching balance for ${token.symbol}:`, error);
}

}

setBalances(result); setLoading(false); console.log('Finished fetching balances:', result); };

fetchBalances();

}, [rpcUrl, account, chainLoading]);

return { balances, loading }; }

// 🏷️ Safe App Badge: //

https://img.shields.io/badge/Safe%20App-Enabled-green?style=flat-square&logo=ethereum&logoColor=whitehttps://img.shields.io/badge/Live-GitHub%20Pages-24292E?style=flat-square&logo=github&logoColor=white![Safe App](https://img.shields.io/badge/Safe%20App-Enabled-green?style=flat-square&logo=ethereum&logoColor=white) git commit -m "docs: add multichain Safe App badge to README"

0_prettify (ubuntu-latest, 24, 1.24).txt

2_validate-links (ubuntu-latest, 3.4).txt

1_codespell (ubuntu-latest).txt

CHANGELOG.md

Contributor guide