-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(TokenField): allow apply balance (#494)
- Loading branch information
1 parent
59ca825
commit 163b874
Showing
6 changed files
with
130 additions
and
33 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
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,20 +1,46 @@ | ||
import { usePress } from '@react-aria/interactions'; | ||
|
||
import { TokenBalanceLabel, TokenBalanceValue, TokenBalanceWrapper } from './TokenBalance.style'; | ||
|
||
interface TokenBalanceProps { | ||
type TokenBalanceProps = { | ||
tokenSymbol: string; | ||
value: string; | ||
valueInUSD: string; | ||
} | ||
value: string | number; | ||
valueInUSD: string | number; | ||
onClickBalance?: () => void; | ||
isDisabled?: boolean; | ||
className?: string; | ||
}; | ||
|
||
const TokenBalance = ({ | ||
tokenSymbol, | ||
value, | ||
valueInUSD, | ||
onClickBalance, | ||
className, | ||
isDisabled | ||
}: TokenBalanceProps): JSX.Element => { | ||
const isClickable = !!onClickBalance && !isDisabled; | ||
const { pressProps } = usePress({ onPress: onClickBalance, isDisabled: !isClickable }); | ||
const balanceValueProps = isClickable | ||
? { | ||
role: 'button', | ||
tabIndex: 0, | ||
'aria-label': 'apply balance', | ||
...pressProps | ||
} | ||
: {}; | ||
|
||
const TokenBalance = ({ tokenSymbol, value, valueInUSD }: TokenBalanceProps): JSX.Element => { | ||
return ( | ||
<TokenBalanceWrapper> | ||
<TokenBalanceWrapper className={className}> | ||
<TokenBalanceLabel>Balance:</TokenBalanceLabel> | ||
<TokenBalanceValue> | ||
{value} {tokenSymbol} ({valueInUSD}) | ||
</TokenBalanceValue> | ||
<dd> | ||
<TokenBalanceValue $clickable={isClickable} {...balanceValueProps}> | ||
{value} {tokenSymbol} ({valueInUSD}) | ||
</TokenBalanceValue> | ||
</dd> | ||
</TokenBalanceWrapper> | ||
); | ||
}; | ||
|
||
export { TokenBalance }; | ||
export type { TokenBalanceProps }; |
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
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
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
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { RefObject } from 'react'; | ||
|
||
/** | ||
* @param {RefObject<HTMLInputElement>} ref - input ref. | ||
* @param {string | ReadonlyArray<string> | number} value - value to be included in the event | ||
* @return {void} - Manually emits onChange event | ||
*/ | ||
const triggerChangeEvent = (ref: RefObject<HTMLInputElement>, value: string | ReadonlyArray<string> | number): void => { | ||
const setValue = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value')?.set; | ||
setValue?.call(ref.current, value); | ||
|
||
const e = new Event('input', { bubbles: true }); | ||
ref.current?.dispatchEvent(e); | ||
}; | ||
|
||
export { triggerChangeEvent }; |
163b874
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
interbtc-ui-interlay-testnet – ./
interbtc-ui-interlay-testnet-git-master-interlay.vercel.app
interbtc-ui-interlay-testnet.vercel.app
testnet.interlay.io
interbtc-ui-interlay-testnet-interlay.vercel.app
163b874
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
interbtc-ui-kintsugi-testnet – ./
interbtc-ui-kintsugi-testnet-interlay.vercel.app
kintnet.interlay.io
interbtc-ui.vercel.app
interbtc-ui-kintsugi-testnet-git-master-interlay.vercel.app