|
| 1 | +--- |
| 2 | +"thirdweb": minor |
| 3 | +--- |
| 4 | +The Connected-details button now shows USD value next to the token balance. |
| 5 | + |
| 6 | +### Breaking change to the AccountBalance |
| 7 | +The formatFn props now takes in an object of type `AccountBalanceInfo`. The old `formatFn` was inflexible because it only allowed you to format the balance value. |
| 8 | +With this new version, you have access to both the balance and symbol. |
| 9 | +```tsx |
| 10 | +import { AccountBalance, type AccountBalanceInfo } from "thirdweb/react"; |
| 11 | + |
| 12 | +<AccountBalance |
| 13 | + // Show the symbol in lowercase, before the balance |
| 14 | + formatFn={(props: AccountBalanceInfo) => `${props.symbol.toLowerCase()} ${props.balance}`} |
| 15 | +/> |
| 16 | +``` |
| 17 | + |
| 18 | +AccountBalance now supports showing the token balance in fiat value (only USD supported at the moment) |
| 19 | +```tsx |
| 20 | +<AccountBalance |
| 21 | + showBalanceInFiat="USD" |
| 22 | +/> |
| 23 | +``` |
| 24 | + |
| 25 | +The `formatFn` prop now takes in an object of type `AccountBalanceInfo` and outputs a string |
| 26 | +```tsx |
| 27 | +import { AccountBalance, type AccountBalanceInfo } from "thirdweb/react"; |
| 28 | + |
| 29 | +<AccountBalance |
| 30 | + formatFn={(props: AccountBalanceInfo) => `${props.balance}---${props.symbol.toLowerCase()}`} |
| 31 | +/> |
| 32 | + |
| 33 | +// Result: 11.12---eth |
| 34 | +``` |
| 35 | + |
| 36 | +### ConnectButton also supports displaying balance in fiat since it uses AccountBalance internally |
| 37 | +```tsx |
| 38 | +<ConnectButton |
| 39 | + // Show USD value on the button |
| 40 | + detailsButton={{ |
| 41 | + showBalanceInFiat: "USD", |
| 42 | + }} |
| 43 | + |
| 44 | + // Show USD value on the modal |
| 45 | + detailsModal={{ |
| 46 | + showBalanceInFiat: "USD", |
| 47 | + }} |
| 48 | +/> |
| 49 | +``` |
| 50 | + |
| 51 | +### Export utils functions: |
| 52 | +formatNumber: Round up a number to a certain decimal place |
| 53 | +```tsx |
| 54 | +import { formatNumber } from "thirdweb/utils"; |
| 55 | +const value = formatNumber(12.1214141, 1); // 12.1 |
| 56 | +``` |
| 57 | + |
| 58 | +shortenLargeNumber: Shorten the string for large value. Mainly used for the AccountBalance's `formatFn` |
| 59 | +```tsx |
| 60 | +import { shortenLargeNumber } from "thirdweb/utils"; |
| 61 | +const numStr = shortenLargeNumber(1_000_000_000) |
| 62 | +``` |
| 63 | + |
| 64 | +### Fix to ConnectButton |
| 65 | +The social image of the Details button now display correctly for non-square image. |
0 commit comments