Skip to content

Commit

Permalink
chore: udpates
Browse files Browse the repository at this point in the history
  • Loading branch information
stackchain committed May 6, 2024
1 parent e446c0e commit da432b9
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 28 deletions.
2 changes: 0 additions & 2 deletions apps/wallet-mobile/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,3 @@ import {YoroiApp} from './src/YoroiApp'
enableMapSet()
BigNumber.config({DECIMAL_PLACES: 19, EXPONENTIAL_AT: [-10, 40]})
AppRegistry.registerComponent(name, () => YoroiApp)

import "./ReactotronConfig"
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export const MediaPreview = ({
? placeholder
: `https://${network}.processed-media.yoroiwallet.com/${policy}/${name}?width=512&height=512&kind=metadata&fit=${contentFit}`

console.log(status, 'status', uri, 'uri')
return (
<View style={{width, height, overflow: 'hidden'}}>
<Image
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export const SelectTokenFromListScreen = () => {

<Counter
fungibilityFilter={fungibilityFilter}
counter={spendableAmounts.length}
counter={filteredAmounts.length}
isSearchOpened={isSearchOpened}
isSearching={isSearching}
/>
Expand Down Expand Up @@ -230,7 +230,8 @@ const SelectAmount = ({amount, disabled}: SelectAmountProps) => {
const {styles} = useStyles()
const navigation = useNavigation<TxHistoryRouteNavigation>()
const {closeSearch} = useSearch()
const {tokenSelectedChanged, amountChanged} = useTransfer()
const {tokenSelectedChanged, amountChanged, targets, selectedTargetIndex} = useTransfer()
const currentAmount = targets[selectedTargetIndex].entry.amounts[amount.info.id]

const isPrimary = isPrimaryToken(amount.info)

Expand All @@ -243,9 +244,15 @@ const SelectAmount = ({amount, disabled}: SelectAmountProps) => {
amountChanged(amount)
navigation.navigate('send-list-amounts-to-send')
} else {
if (currentAmount == null) {
amountChanged({
info: amount.info,
quantity: 0n,
})
}
navigation.navigate('send-edit-amount')
}
}, [amount, amountChanged, closeSearch, navigation, tokenSelectedChanged])
}, [amount, amountChanged, closeSearch, currentAmount, navigation, tokenSelectedChanged])

return (
<TouchableOpacity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const EditAmountScreen = () => {

const [quantity, setQuantity] = React.useState(initialQuantity)
const [inputValue, setInputValue] = React.useState(splitBigInt(initialQuantity, amount.info.decimals).bn.toFormat())
const spendable = available - primaryBreakdown.lockedAsStorageCost
const spendable = isPrimary ? available - primaryBreakdown.lockedAsStorageCost : available

useOverridePreviousSendTxRoute(initialQuantity === 0n ? 'send-select-token-from-list' : 'send-list-amounts-to-send')

Expand All @@ -54,54 +54,65 @@ export const EditAmountScreen = () => {
const isUnableToSpend = isPrimary && quantity > spendable
const isZero = quantity === 0n

const onChangeQuantity = (text: string) => {
try {
const [newInputValue, newQuantity] = parseInputToBigInt({
input: text,
decimalPlaces: amount.info.decimals,
format: numberLocale,
})
setInputValue(newInputValue)
setQuantity(newQuantity)
} catch (error) {
Logger.error('EditAmountScreen::onChangeQuantity', error)
}
}
const onMaxBalance = () => {
const handleOnChangeQuantity = React.useCallback(
(text: string) => {
try {
const [newInputValue, newQuantity] = parseInputToBigInt({
input: text,
decimalPlaces: amount.info.decimals,
format: numberLocale,
})
setInputValue(newInputValue)
setQuantity(newQuantity)
} catch (error) {
Logger.error('EditAmountScreen::onChangeQuantity', error)
}
},
[amount.info.decimals, numberLocale],
)

const handleOnMaxBalance = React.useCallback(() => {
const [newInputValue, newQuantity] = parseInputToBigInt({
input: spendable.toString(),
decimalPlaces: amount.info.decimals,
format: numberLocale,
})
setInputValue(newInputValue)
setQuantity(newQuantity)
}
const onApply = () => {
}, [amount.info.decimals, numberLocale, spendable])

const handleOnApply = React.useCallback(() => {
amountChanged({
info: amount.info,
quantity,
})
navigateTo.selectedTokens()
}
}, [amount.info, amountChanged, navigateTo, quantity])

return (
<View style={styles.container}>
<KeyboardAvoidingView style={{flex: 1}}>
<ScrollView style={styles.scrollView} bounces={false}>
<Spacer height={16} />

<TokenAmountItem amount={amount} ignorePrivacy />
<TokenAmountItem
amount={{
info: amount.info,
quantity: spendable,
}}
ignorePrivacy
/>

<Spacer height={40} />

<AmountInput onChange={onChangeQuantity} value={inputValue} ticker={amount.info.ticker} />
<AmountInput onChange={handleOnChangeQuantity} value={inputValue} ticker={amount.info.ticker} />

<Center>
{isPrimary && <PairedBalance amount={amount} ignorePrivacy />}

<Spacer height={22} />

{!isPrimary && <MaxBalanceButton onPress={onMaxBalance} />}
{!isPrimary && <MaxBalanceButton onPress={handleOnMaxBalance} />}

<Spacer height={22} />

Expand All @@ -115,7 +126,7 @@ export const EditAmountScreen = () => {

<Actions>
<ApplyButton
onPress={onApply}
onPress={handleOnApply}
title={strings.apply.toLocaleUpperCase()}
shelleyTheme
disabled={isUnableToSpend || !hasBalance || isZero}
Expand Down

0 comments on commit da432b9

Please sign in to comment.