Skip to content

Commit

Permalink
fix wallet address in bridge transactions (#1416)
Browse files Browse the repository at this point in the history
Co-authored-by: Zach Couchman <[email protected]>
  • Loading branch information
ZacharyCouchman and ZacharyCouchman authored Jan 25, 2024
1 parent bc9da87 commit f36c9c9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ type TransactionListProps = {
transactions: Transaction[],
knownTokenMap: KnownNetworkMap,
isPassport: boolean;
walletAddress: string;
};

export function TransactionList({
checkout,
transactions,
knownTokenMap,
isPassport,
walletAddress,
}: TransactionListProps) {
const { cryptoFiatState } = useContext(CryptoFiatContext);
const { t } = useTranslation();
Expand Down Expand Up @@ -59,7 +61,7 @@ export function TransactionList({
return (
<Box sx={transactionsListStyle(isPassport)}>
<Box sx={headingStyles}>
<EllipsizedText leftSideLength={6} rightSideLength={4} text="0x1234567890" />
<EllipsizedText leftSideLength={6} rightSideLength={4} text={walletAddress} />
</Box>
<Box
testId="move-transaction-list"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ export function Transactions({ checkout }: TransactionsProps) {

const [loading, setLoading] = useState(true);
const [provider, setProvider] = useState<Web3Provider | undefined>(undefined);
const [walletAddress, setWalletAddress] = useState('');
const [knownTokenMap, setKnownTokenMap] = useState<KnownNetworkMap | undefined>(undefined);
const [txs, setTxs] = useState<Transaction[]>([]);

const walletAddress = useCallback(async () => await provider?.getSigner().getAddress(), [provider]);
const isPassport = isPassportProvider(provider);

// Fetch the tokens for the root chain using the allowed tokens.
Expand Down Expand Up @@ -87,13 +87,12 @@ export function Transactions({ checkout }: TransactionsProps) {
const childChainTokensHashmap = useCallback(async () => {
if (!provider) return {};

const address = await walletAddress();
if (!address) return {};
if (!walletAddress) return {};

const childChainId = getL2ChainId(checkout.config);

try {
const data = await checkout.getAllBalances({ provider, walletAddress: address, chainId: childChainId });
const data = await checkout.getAllBalances({ provider, walletAddress, chainId: childChainId });
return data.balances.reduce((out, current) => {
// eslint-disable-next-line no-param-reassign
out[current.token.address!.toLowerCase()] = current.token;
Expand All @@ -108,7 +107,10 @@ export function Transactions({ checkout }: TransactionsProps) {

const updateAndConnectProvider = useCallback(async (walletProviderName: WalletProviderName) => {
try {
setProvider(await createAndConnectToProvider(checkout, walletProviderName));
const localProvider = await createAndConnectToProvider(checkout, walletProviderName);
const address = await localProvider?.getSigner().getAddress() ?? '';
setProvider(localProvider);
setWalletAddress(address.toLowerCase());
} catch (error) {
// eslint-disable-next-line no-console
console.error(error);
Expand Down Expand Up @@ -203,10 +205,9 @@ export function Transactions({ checkout }: TransactionsProps) {
};

const fetchData = async () => {
const address = await walletAddress();
if (!address) return undefined;
if (!walletAddress) return undefined;

const localTxs = await getTransactionsDetails(checkout.config.environment, address);
const localTxs = await getTransactionsDetails(checkout.config.environment, walletAddress);

const tokensWithChainSlug: { [k: string]: string } = {};
localTxs.result.forEach((txn) => {
Expand Down Expand Up @@ -266,6 +267,7 @@ export function Transactions({ checkout }: TransactionsProps) {
transactions={txs}
knownTokenMap={knownTokenMap}
isPassport={isPassport}
walletAddress={walletAddress}
/>
)}
{provider && !loading && txs.length === 0 && (
Expand Down

0 comments on commit f36c9c9

Please sign in to comment.