-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ui-react): prevent re-calculate friendly address on wallet unchan…
…ged in useTonAddress
- Loading branch information
Showing
1 changed file
with
13 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,23 @@ | ||
import { CHAIN, toUserFriendlyAddress } from '@tonconnect/ui'; | ||
import { useTonWallet } from './useTonWallet'; | ||
import { useMemo } from 'react'; | ||
|
||
/** | ||
* Use it to get user's current ton wallet address. If wallet is not connected hook will return empty string. | ||
* @param [userFriendly=true] allows to choose format of the address. | ||
*/ | ||
export function useTonAddress(userFriendly = true): string { | ||
const wallet = useTonWallet(); | ||
|
||
if (wallet) { | ||
return userFriendly | ||
? toUserFriendlyAddress(wallet.account.address, wallet.account.chain === CHAIN.TESTNET) | ||
: wallet.account.address; | ||
} else { | ||
return ''; | ||
} | ||
return useMemo(() => { | ||
if (wallet) { | ||
return userFriendly | ||
? toUserFriendlyAddress( | ||
wallet.account.address, | ||
wallet.account.chain === CHAIN.TESTNET | ||
) | ||
: wallet.account.address; | ||
} else { | ||
return ''; | ||
} | ||
}, [wallet, userFriendly, wallet?.account.address, wallet?.account.chain]); | ||
} |