MCPcopy
hub / github.com/BlueWallet/BlueWallet / AmountInput

Function AmountInput

components/AmountInput.tsx:103–481  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

101};
102
103export const AmountInput: React.FC<AmountInputProps> = props => {
104 const textInputRef = useRef<TextInput>(null);
105 const { colors } = useTheme();
106 const amount = props.amount || '0'; // internally amount is aways a string with a correct number
107 const {
108 onChangeText,
109 unit,
110 onAmountUnitChange,
111 disabled = false,
112 isLoading = false,
113 maxSendableAmount,
114 isMaxAmountEstimate,
115 style: styleOverride,
116 ...otherProps
117 } = props;
118 const [isRateBeingUpdatedLocal, setIsRateBeingUpdatedLocal] = useState(false);
119 const [outdatedRefreshRate, setOutdatedRefreshRate] = useState<CurrencyRate | undefined>();
120
121 const maxLength = useMemo(() => {
122 switch (unit) {
123 case BitcoinUnit.BTC:
124 return 11;
125 case BitcoinUnit.SATS:
126 return 15;
127 default:
128 return 15;
129 }
130 }, [unit]);
131
132 const displayAmount = useMemo(() => {
133 if (amount === BitcoinUnit.MAX) {
134 return loc.units.MAX;
135 }
136
137 return parseFloat(amount) >= 0 ? String(amount) : undefined;
138 }, [amount]);
139
140 const inputFontSize = useMemo(() => (amount.length > 10 ? 20 : 36), [amount.length]);
141
142 const measureAmountText = displayAmount && displayAmount.length > 0 ? displayAmount : '0';
143
144 const inputTextAlign = useMemo((): 'left' | 'right' | 'center' => {
145 if (amount === BitcoinUnit.MAX) return 'center';
146 return unit === BitcoinUnit.LOCAL_CURRENCY ? 'left' : 'right';
147 }, [amount, unit]);
148
149 const secondaryDisplayCurrency = useMemo(() => {
150 if (amount === BitcoinUnit.MAX) {
151 return '';
152 }
153 switch (unit) {
154 case BitcoinUnit.BTC: {
155 const sat = new BigNumber(amount).multipliedBy(100000000).toNumber();
156 return formatBalanceWithoutSuffix(sat, BitcoinUnit.LOCAL_CURRENCY, false);
157 }
158 case BitcoinUnit.SATS:
159 return formatBalanceWithoutSuffix(Number(amount), BitcoinUnit.LOCAL_CURRENCY, false);
160 case BitcoinUnit.LOCAL_CURRENCY: {

Callers

nothing calls this directly

Calls 13

useThemeFunction · 0.90
satoshiToBTCFunction · 0.90
fiatToBTCFunction · 0.90
removeTrailingZerosFunction · 0.90
isRateOutdatedFunction · 0.90
mostRecentFetchedRateFunction · 0.90
updateExchangeRateFunction · 0.90
formatBalancePlainFunction · 0.90
getCurrencySymbolFunction · 0.90
onChangeTextFunction · 0.85
triggerHapticFeedbackFunction · 0.85

Tested by

no test coverage detected