Skip to content

Commit

Permalink
fix: <ConnectButton.Custom /> not displaying balance (#1760)
Browse files Browse the repository at this point in the history
* chore: always show balance when using ConnectButton.Custom

* chore: force show balance for <ConnectButton.Custom>

* chore: ready before rendering component

* chore: render JSX component

* chore: tweak changelog

---------

Co-authored-by: Daniel Sinclair <d@niel.nyc>
  • Loading branch information
magiziz and DanielSinclair authored Feb 8, 2024
1 parent 4221a1c commit 33a8266
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/lazy-badgers-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rainbow-me/rainbowkit": patch
---

Fixed a bug where `account.displayBalance` for the `<ConnectButton.Custom>` component would sometimes be undefined.
14 changes: 11 additions & 3 deletions packages/rainbowkit/src/components/ConnectButton/ConnectButton.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useContext, useEffect } from 'react';
import React, { useContext, useEffect, useState } from 'react';
import {
ResponsiveValue,
mapResponsiveValue,
Expand Down Expand Up @@ -42,14 +42,17 @@ export function ConnectButton({
const chains = useRainbowKitChains();
const connectionStatus = useConnectionStatus();
const { setShowBalance } = useShowBalance();
const [ready, setReady] = useState(false);

const { i18n } = useContext(I18nContext);

// biome-ignore lint/correctness/useExhaustiveDependencies: <explanation>
useEffect(() => {
setShowBalance(showBalance);
if (!ready) setReady(true);
}, [showBalance, setShowBalance]);

return (
return ready ? (
<ConnectButtonRenderer>
{({
account,
Expand Down Expand Up @@ -263,7 +266,10 @@ export function ConnectButton({
background="accentColor"
borderRadius="connectButton"
boxShadow="connectButton"
className={touchableStyles({ active: 'shrink', hover: 'grow' })}
className={touchableStyles({
active: 'shrink',
hover: 'grow',
})}
color="accentColorForeground"
fontFamily="body"
fontWeight="bold"
Expand All @@ -284,6 +290,8 @@ export function ConnectButton({
);
}}
</ConnectButtonRenderer>
) : (
<></>
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export function ConnectButtonRenderer({
? normalizeResponsiveValue(showBalance)[
isMobile() ? 'smallScreen' : 'largeScreen'
]
: false;
: true;
const { data: balanceData } = useBalance({
address: shouldShowBalance ? address : undefined,
});
Expand Down

0 comments on commit 33a8266

Please sign in to comment.