Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into refactor/bottom-mo…
Browse files Browse the repository at this point in the history
…dals
  • Loading branch information
banklesss committed Oct 10, 2023
2 parents 16e43ac + 0ecf95c commit e29c204
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 104 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import {getMinAdaReceiveAfterSlippage, useSwap} from '@yoroi/swap'
import {useSwap} from '@yoroi/swap'
import React from 'react'
import {StyleSheet, TouchableOpacity, View} from 'react-native'

import {Icon, Spacer, Text} from '../../../../components'
import {AmountItem} from '../../../../components/AmountItem/AmountItem'
import {BottomSheetModal} from '../../../../components/BottomSheetModal'
import {useLanguage} from '../../../../i18n'
import {useSelectedWallet} from '../../../../SelectedWallet'
import {COLORS} from '../../../../theme'
import {useTokenInfo} from '../../../../yoroi-wallets/hooks'
Expand All @@ -20,7 +19,6 @@ export const TransactionSummary = () => {
})
const strings = useStrings()
const wallet = useSelectedWallet()
const {numberLocale} = useLanguage()
const {orderData} = useSwap()
const {amounts, selectedPoolCalculation} = orderData

Expand All @@ -39,11 +37,9 @@ export const TransactionSummary = () => {
},
{
label: strings.swapMinReceivedTitle,
value: `${getMinAdaReceiveAfterSlippage(
amounts.buy.quantity,
orderData.slippage,
value: `${Quantities.format(
selectedPoolCalculation?.buyAmountWithSlippage?.quantity ?? Quantities.zero,
buyTokenInfo.decimals ?? 0,
numberLocale,
)} ${tokenToBuyName}`,
info: strings.swapMinReceived,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const EditLimitPrice = () => {
const {numberLocale} = useLanguage()
const [text, setText] = React.useState('')
const wallet = useSelectedWallet()
const inputRef = React.useRef<TextInput>(null)

const {orderData, limitPriceChanged} = useSwap()
const sellTokenInfo = useTokenInfo({wallet, tokenId: orderData.amounts.sell.tokenId})
Expand All @@ -33,7 +34,8 @@ export const EditLimitPrice = () => {

React.useEffect(() => {
if (orderData.type === 'limit') {
setText(Quantities.format(orderData.limitPrice ?? Quantities.zero, denomination, PRECISION))
!inputRef?.current?.isFocused() &&
setText(Quantities.format(orderData.limitPrice ?? Quantities.zero, denomination, PRECISION))
} else {
setText(
Quantities.format(orderData.selectedPoolCalculation?.prices.market ?? Quantities.zero, denomination, PRECISION),
Expand All @@ -54,7 +56,7 @@ export const EditLimitPrice = () => {
<Text style={styles.label}>{disabled ? strings.marketPrice : strings.limitPrice}</Text>

<View style={styles.content}>
<AmountInput onChange={onChange} value={text} editable={!disabled} />
<AmountInput onChange={onChange} value={text} editable={!disabled} inputRef={inputRef} />

<View style={[styles.textWrapper, disabled && styles.disabled]}>
<Text style={styles.text}>
Expand All @@ -70,8 +72,9 @@ type AmountInputProps = {
value?: string
onChange(value: string): void
editable: boolean
inputRef?: React.RefObject<TextInput>
}
const AmountInput = ({onChange, value, editable}: AmountInputProps) => {
const AmountInput = ({onChange, value, editable, inputRef}: AmountInputProps) => {
return (
<TextInput
keyboardType="numeric"
Expand All @@ -84,6 +87,7 @@ const AmountInput = ({onChange, value, editable}: AmountInputProps) => {
style={styles.amountInput}
underlineColorAndroid="transparent"
editable={editable}
ref={inputRef}
/>
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {getMinAdaReceiveAfterSlippage, useSwap} from '@yoroi/swap'
import {useSwap} from '@yoroi/swap'
import {capitalize} from 'lodash'
import React from 'react'
import {StyleSheet, Text, TouchableOpacity, View} from 'react-native'
Expand All @@ -10,7 +10,6 @@ import {
HiddenInfoWrapper,
Spacer,
} from '../../../../../../components'
import {useLanguage} from '../../../../../../i18n'
import {useSelectedWallet} from '../../../../../../SelectedWallet'
import {COLORS} from '../../../../../../theme'
import {useTokenInfo} from '../../../../../../yoroi-wallets/hooks'
Expand All @@ -22,7 +21,6 @@ import {useSwapTouched} from '../../../../common/SwapFormProvider'

export const ShowPoolActions = () => {
const navigateTo = useNavigateTo()
const {numberLocale} = useLanguage()
const {orderData} = useSwap()
const strings = useStrings()
const {isBuyTouched, isSellTouched, isPoolTouched} = useSwapTouched()
Expand Down Expand Up @@ -90,11 +88,9 @@ export const ShowPoolActions = () => {
selectedPoolCalculation.pool.batcherFee.quantity,
Number(wallet.primaryTokenInfo.decimals),
)}
minReceived={getMinAdaReceiveAfterSlippage(
amounts.buy.quantity,
orderData.slippage,
minReceived={Quantities.format(
selectedPoolCalculation.buyAmountWithSlippage.quantity,
buyTokenInfo.decimals ?? 0,
numberLocale,
)}
minAda={Quantities.format(
selectedPoolCalculation.pool.deposit.quantity,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {useSwap} from '@yoroi/swap'
import React from 'react'
import {StyleSheet, Text} from 'react-native'
import {Keyboard, StyleSheet, Text} from 'react-native'
import {TouchableOpacity} from 'react-native-gesture-handler'

import {COLORS} from '../../../../../../theme'
Expand All @@ -13,6 +13,7 @@ export const ClearQuantities = () => {
const {poolDefaulted} = useSwapTouched()

const handleReset = () => {
Keyboard.dismiss()
resetQuantities()
poolDefaulted()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {useSwap, useSwapPoolsByPair} from '@yoroi/swap'
import React from 'react'
import {StyleSheet, View} from 'react-native'
import {Keyboard, StyleSheet, View} from 'react-native'
import {TouchableOpacity} from 'react-native-gesture-handler'

import {Icon} from '../../../../../../components'
Expand Down Expand Up @@ -40,6 +40,7 @@ export const TopTokenActions = () => {
}

const handleRefresh = () => {
Keyboard.dismiss()
refetch()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,74 +4,74 @@
"defaultMessage": "!!!Select token",
"file": "src/features/Swap/common/AmountCard/AmountCard.tsx",
"start": {
"line": 134,
"line": 135,
"column": 15,
"index": 4170
"index": 4171
},
"end": {
"line": 137,
"line": 138,
"column": 3,
"index": 4253
"index": 4254
}
},
{
"id": "swap.swapScreen.currentBalance",
"defaultMessage": "!!!Current Balance",
"file": "src/features/Swap/common/AmountCard/AmountCard.tsx",
"start": {
"line": 138,
"line": 139,
"column": 18,
"index": 4273
"index": 4274
},
"end": {
"line": 141,
"line": 142,
"column": 3,
"index": 4362
"index": 4363
}
},
{
"id": "swap.swapScreen.notEnoughBalance",
"defaultMessage": "!!!Not enough balance",
"file": "src/features/Swap/common/AmountCard/AmountCard.tsx",
"start": {
"line": 142,
"line": 143,
"column": 20,
"index": 4384
"index": 4385
},
"end": {
"line": 145,
"line": 146,
"column": 3,
"index": 4478
"index": 4479
}
},
{
"id": "swap.swapScreen.notEnoughSupply",
"defaultMessage": "!!!Not enough supply in the pool",
"file": "src/features/Swap/common/AmountCard/AmountCard.tsx",
"start": {
"line": 146,
"line": 147,
"column": 19,
"index": 4499
"index": 4500
},
"end": {
"line": 149,
"line": 150,
"column": 3,
"index": 4603
"index": 4604
}
},
{
"id": "swap.swapScreen.noPool",
"defaultMessage": "!!! This pair is not available in any liquidity pool",
"file": "src/features/Swap/common/AmountCard/AmountCard.tsx",
"start": {
"line": 150,
"line": 151,
"column": 10,
"index": 4615
"index": 4616
},
"end": {
"line": 153,
"line": 154,
"column": 3,
"index": 4730
"index": 4731
}
}
]

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion packages/swap/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export {apiMocks} from './adapters/openswap-api/api.mocks'
// orders amounts
export {getBuyAmount} from './helpers/orders/amounts/getBuyAmount'
export {getSellAmount} from './helpers/orders/amounts/getSellAmount'
export {getMinAdaReceiveAfterSlippage} from './helpers/orders/amounts/getMinAdaReceiveAfterSlippage'
export {getQuantityWithSlippage} from './helpers/orders/amounts/getQuantityWithSlippage'
// orders factories
export {makePossibleMarketOrder} from './helpers/orders/factories/makePossibleMarketOrder'
Expand Down

0 comments on commit e29c204

Please sign in to comment.