Skip to content

Commit

Permalink
chore: CR updates
Browse files Browse the repository at this point in the history
  • Loading branch information
stackchain committed Jan 28, 2025
1 parent 197b35c commit e3d7ab2
Show file tree
Hide file tree
Showing 15 changed files with 43 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {useTheme} from '@yoroi/theme'
import {Chain, Portfolio} from '@yoroi/types'
import React from 'react'
import * as React from 'react'
import {StyleSheet, View} from 'react-native'

import {Button, ButtonType} from '../../../../components/Button/Button'
Expand Down
2 changes: 1 addition & 1 deletion apps/wallet-mobile/src/features/Swap/SwapNavigator.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {createMaterialTopTabNavigator} from '@react-navigation/material-top-tabs'
import {EventArg} from '@react-navigation/native'
import {useTheme} from '@yoroi/theme'
import React from 'react'
import * as React from 'react'
import {Keyboard, StyleSheet} from 'react-native'
import {SafeAreaView} from 'react-native-safe-area-context'

Expand Down
21 changes: 10 additions & 11 deletions apps/wallet-mobile/src/features/Swap/common/Provider/Provider.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {getProviderUrl} from '@yoroi/swap'
import {useTheme} from '@yoroi/theme'
import {Swap} from '@yoroi/types'
import React from 'react'
import * as React from 'react'
import {Linking, StyleSheet, Text, TouchableOpacity, View} from 'react-native'

import {Spacer} from '../../../../components/Spacer/Spacer'
Expand All @@ -10,13 +10,14 @@ import {ProviderIcon} from './ProviderIcon'
export const Provider = ({
provider,
append = '',
noLink = false,
preventOpenLink = false,
}: {
provider: Swap.Provider
append?: string
noLink?: boolean
preventOpenLink?: boolean
}) => {
const styles = useStyles()
const formattedName = `${provider.charAt(0).toUpperCase()}${provider.slice(1).replace(/-/, ' ')}${append}`

return (
<View style={styles.container}>
Expand All @@ -27,11 +28,9 @@ export const Provider = ({
<TouchableOpacity
onPress={() => Linking.openURL(getProviderUrl(provider))}
style={styles.button}
disabled={noLink}
disabled={preventOpenLink}
>
<Text style={[styles.text, !noLink && styles.link]}>{`${provider.charAt(0).toUpperCase()}${provider
.slice(1)
.replace(/-/, ' ')}${append}`}</Text>
<Text style={[styles.text, !preventOpenLink && styles.link]}>{formattedName}</Text>
</TouchableOpacity>
</View>
)
Expand All @@ -41,8 +40,8 @@ const useStyles = () => {
const {color, atoms} = useTheme()
const styles = StyleSheet.create({
button: {
alignItems: 'center',
justifyContent: 'center',
...atoms.align_center,
...atoms.justify_center,
},
text: {
...atoms.py_2xs,
Expand All @@ -53,8 +52,8 @@ const useStyles = () => {
color: color.text_primary_medium,
},
container: {
flexDirection: 'row',
alignItems: 'center',
...atoms.flex_row,
...atoms.align_center,
},
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Swap} from '@yoroi/types'
import React, {FunctionComponent} from 'react'
import * as React from 'react'

import {Icon} from '../../../../components/Icon'

Expand All @@ -13,7 +13,7 @@ export const ProviderIcon = ({provider, size}: Props) => {
return <IconVariant size={size} />
}

const icons: Record<Swap.Provider, FunctionComponent<{size?: number}>> = {
const icons: Record<Swap.Provider, React.FunctionComponent<{size?: number}>> = {
[Swap.Provider.Muesliswap_v2]: Icon.MuesliSwap,
[Swap.Provider.Muesliswap_clp]: Icon.MuesliSwap,
[Swap.Provider.Minswap_v1]: Icon.MinSwap,
Expand Down
6 changes: 3 additions & 3 deletions apps/wallet-mobile/src/features/Swap/common/SwapProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {primaryTokenId} from '@yoroi/portfolio'
import {swapManagerMaker, swapStorageMaker} from '@yoroi/swap'
import {Api, Portfolio, Swap} from '@yoroi/types'
import {produce} from 'immer'
import React from 'react'
import * as React from 'react'
import {TextInput} from 'react-native'
import {useQuery} from 'react-query'

Expand Down Expand Up @@ -476,7 +476,7 @@ type SwapState = {

export type SwapContext = SwapState & {
providers: Swap.ProvidersResponse
tokenInfos: Map<`${string}.${string}`, Portfolio.Token.Info>
tokenInfos: Map<Portfolio.Token.Id, Portfolio.Token.Info>
tokenInInputRef: React.RefObject<TextInput> | undefined
tokenOutInputRef: React.RefObject<TextInput> | undefined
wantedPriceInputRef: React.RefObject<TextInput> | undefined
Expand All @@ -492,7 +492,7 @@ export type SwapContext = SwapState & {
const SwapContext = React.createContext<SwapContext>({
...defaultState,
providers: [],
tokenInfos: new Map<`${string}.${string}`, Portfolio.Token.Info>(),
tokenInfos: new Map<Portfolio.Token.Id, Portfolio.Token.Info>(),
tokenInInputRef: undefined,
tokenOutInputRef: undefined,
wantedPriceInputRef: undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const ProviderSplits = () => {
<Provider
provider={dex}
append={`${swapForm.selectedDex.isTouched ? '' : ` ${strings.autoPool}`}`}
noLink
preventOpenLink
/>
)}
</View>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {useNavigation} from '@react-navigation/native'
import {useTheme} from '@yoroi/theme'
import React from 'react'
import * as React from 'react'
import {FlatList, StyleSheet, Text, TouchableOpacity, View} from 'react-native'
import {SafeAreaView} from 'react-native-safe-area-context'

Expand Down Expand Up @@ -32,7 +32,7 @@ export const SelectProviderScreen = () => {
}}
>
<View style={styles.row}>
<Provider provider={item.provider} noLink />
<Provider provider={item.provider} preventOpenLink />

<Text style={styles.aggregator}>{item.aggregator}</Text>
</View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ export const StartSwapOrderScreen = () => {
const navigate = useNavigateTo()
const {openModal} = useModal()

const amount = balances.records.get(swapForm.tokenInInput.tokenId ?? 'unknown.') ?? {
info: swapForm.tokenInfos.get(swapForm.tokenInInput.tokenId ?? 'unknown.'),
quantity: balances.records.get(swapForm.tokenInInput.tokenId ?? 'unknown.')?.quantity,
}

return (
<View style={[styles.root, styles.flex]}>
<ScrollView style={styles.padding}>
Expand Down Expand Up @@ -76,12 +81,7 @@ export const StartSwapOrderScreen = () => {
label={strings.swapFrom}
onChange={(value) => swapForm.dispatch({type: 'TokenInAmountChanged', value})}
value={swapForm.tokenInInput.value}
amount={
balances.records.get(swapForm.tokenInInput.tokenId ?? 'unknown.') ?? {
info: swapForm.tokenInfos.get(swapForm.tokenInInput.tokenId ?? 'unknown.'),
quantity: balances.records.get(swapForm.tokenInInput.tokenId ?? 'unknown.')?.quantity,
}
}
amount={amount}
wallet={wallet}
navigateTo={navigate.selectSellToken}
touched={swapForm.tokenInInput.isTouched}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {isLeft} from '@yoroi/common'
import {useTheme} from '@yoroi/theme'
import {Api, Portfolio, Swap} from '@yoroi/types'
import React from 'react'
import * as React from 'react'
import {ErrorBoundary} from 'react-error-boundary'
import {useIntl} from 'react-intl'
import {FlatList, Linking, StyleSheet, Text, TouchableOpacity, View} from 'react-native'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {useTheme} from '@yoroi/theme'
import {Swap} from '@yoroi/types'
import React from 'react'
import * as React from 'react'
import {StyleSheet, Text, View} from 'react-native'

import {Button, ButtonType} from '../../../../components/Button/Button'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {useTheme} from '@yoroi/theme'
import React from 'react'
import * as React from 'react'
import {StyleSheet, useWindowDimensions, View, ViewProps} from 'react-native'
import {ScrollView} from 'react-native-gesture-handler'
import {SafeAreaView} from 'react-native-safe-area-context'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {useTheme} from '@yoroi/theme'
import {capitalize} from 'lodash'
import React from 'react'
import * as React from 'react'
import {StyleSheet, Text, View} from 'react-native'

import {Divider} from '../../../../components/Divider/Divider'
Expand Down
19 changes: 10 additions & 9 deletions packages/swap/src/adapters/api/dexhunter/api-maker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,14 @@ const baseUrls = {
} as const

const apiPaths = {
tokens: '/swap/tokens', // GET
cancel: '/swap/cancel', // POST
estimate: '/swap/estimate', // POST
limitBuild: '/swap/limit/build', // POST
limitEstimate: '/swap/limit/estimate', // POST
orders: ({address}: {address: string}) => `/swap/orders/${address}`, // GET
reverseEstimate: '/swap/reverseEstimate', // POST
build: '/swap/build', // POST
sign: '/swap/sign', // POST
tokens: '/swap/tokens',
orders: ({address}: {address: string}) => `/swap/orders/${address}`,

cancel: '/swap/cancel',
estimate: '/swap/estimate',
limitBuild: '/swap/limit/build',
limitEstimate: '/swap/limit/estimate',
reverseEstimate: '/swap/reverseEstimate',
build: '/swap/build',
sign: '/swap/sign',
} as const
1 change: 1 addition & 0 deletions packages/swap/src/adapters/api/dexhunter/transformers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const transformSplit = ({
priceDistortion: price_distortion,
priceImpact: price_impact,
})

export const transformersMaker = ({
primaryTokenInfo,
address,
Expand Down
2 changes: 2 additions & 0 deletions packages/swap/src/adapters/api/muesliswap/transformers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ export const transformersMaker = ({

const isPrimary = id === primaryTokenInfo.id
if (isPrimary) return primaryTokenInfo

if (decimals === null) return null

return {
id,
fingerprint: '',
Expand Down

0 comments on commit e3d7ab2

Please sign in to comment.