Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: swap refactor (#3731) #3799

Open
wants to merge 28 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
197b35c
chore: swap refactor (#3731)
jorbuedo Jan 27, 2025
e3d7ab2
chore: CR updates
stackchain Jan 28, 2025
1eee3cc
launch swap from portfolio
jorbuedo Jan 29, 2025
c9079ac
remove old files
jorbuedo Jan 29, 2025
e02bbbf
Rename providersplits
jorbuedo Jan 29, 2025
6c02c5f
replace .unknown
jorbuedo Jan 29, 2025
b874397
adds warn limit price
jorbuedo Jan 29, 2025
2ab8b19
rename dispatch
jorbuedo Jan 29, 2025
ec93ed7
fix actions to swap
jorbuedo Jan 29, 2025
311d4f7
remove log
jorbuedo Jan 29, 2025
1277848
pr fixes
jorbuedo Jan 29, 2025
dc3e84a
revert internal address
jorbuedo Jan 29, 2025
453eba8
failed tx
jorbuedo Jan 29, 2025
7d4afd3
Merge branch 'develop' into refactor/swap-module
jorbuedo Jan 29, 2025
9faf8cb
Merge branch 'develop' into refactor/swap-module
jorbuedo Jan 30, 2025
db0dbe4
Merge branch 'develop' into refactor/swap-module
jorbuedo Jan 30, 2025
dfed15e
Merge branch 'develop' into refactor/swap-module
jorbuedo Jan 31, 2025
b0f0b20
more undefinedToken
jorbuedo Jan 31, 2025
2999601
wip
jorbuedo Jan 31, 2025
8a6466c
chore(swap): upd storage to consume parser from common pkg
stackchain Jan 30, 2025
370a520
refactor(swap): types
stackchain Feb 3, 2025
e9a007f
chore(swap): README.md update for glossary
stackchain Feb 3, 2025
484e88c
Merge branch 'develop' into refactor/swap-module
jorbuedo Feb 4, 2025
86167a9
fix wrong imports
jorbuedo Feb 4, 2025
5e77287
Use ascii names for unkown tokens
jorbuedo Feb 4, 2025
8272f79
fix token info transformer
jorbuedo Feb 5, 2025
3a937f6
fix tests
jorbuedo Feb 5, 2025
9056d63
CR: update
banklesss Feb 5, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions apps/wallet-mobile/.storybook/storybook.requires.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

232 changes: 100 additions & 132 deletions apps/wallet-mobile/src/WalletNavigator.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
import {BottomTabBar, BottomTabBarProps, createBottomTabNavigator} from '@react-navigation/bottom-tabs'
import {useFocusEffect} from '@react-navigation/native'
import {createStackNavigator} from '@react-navigation/stack'
import {
milkTokenId,
supportedProviders,
swapApiMaker,
swapManagerMaker,
SwapProvider,
swapStorageMaker,
} from '@yoroi/swap'
import {useTheme} from '@yoroi/theme'
import {Swap} from '@yoroi/types'
import React from 'react'
import {defineMessages, useIntl} from 'react-intl'
import {Keyboard, Platform, StyleSheet, View} from 'react-native'
Expand All @@ -30,10 +21,9 @@ import {SettingsScreenNavigator} from './features/Settings/SettingsScreenNavigat
import {NetworkTag} from './features/Settings/useCases/changeAppSettings/ChangeNetwork/NetworkTag'
import {SetupWalletNavigator} from './features/SetupWallet/SetupWalletNavigator'
import {GovernanceNavigator} from './features/Staking/Governance/GovernanceNavigator'
import {SwapFormProvider} from './features/Swap/common/SwapFormProvider'
import {SwapProvider} from './features/Swap/common/SwapProvider'
import {ToggleAnalyticsSettingsNavigator} from './features/ToggleAnalyticsSettings'
import {TxHistoryNavigator} from './features/Transactions/TxHistoryNavigator'
import {useSelectedWallet} from './features/WalletManager/common/hooks/useSelectedWallet'
import {SelectWalletFromList} from './features/WalletManager/useCases/SelectWalletFromListScreen/SelectWalletFromListScreen'
import {useMetrics} from './kernel/metrics/metricsManager'
import {
Expand All @@ -43,7 +33,6 @@ import {
WalletTabRoutes,
} from './kernel/navigation'
import {DashboardNavigator} from './legacy/Dashboard/DashboardNavigator'
import {useFrontendFees, useStakingKey} from './yoroi-wallets/hooks'

const Tab = createBottomTabNavigator<WalletTabRoutes>()

Expand All @@ -52,8 +41,6 @@ const TabBarWithHiddenContent = (props: BottomTabBarProps) => {
return shouldShow ? <BottomTabBar {...props} /> : null
}

const aggregator: Swap.Aggregator = 'muesliswap'

const WalletTabNavigator = () => {
const strings = useStrings()
const {colors, styles} = useStyles()
Expand Down Expand Up @@ -83,127 +70,108 @@ const WalletTabNavigator = () => {
}, [track]),
)

// swap
const {wallet} = useSelectedWallet()
const {frontendFees} = useFrontendFees(wallet)
const stakingKey = useStakingKey(wallet)
const swapManager = React.useMemo(() => {
const aggregatorTokenId = wallet.isMainnet ? milkTokenId.mainnet : milkTokenId.preprod
const swapStorage = swapStorageMaker()
const swapApi = swapApiMaker({
isMainnet: wallet.isMainnet,
stakingKey,
primaryTokenInfo: wallet.portfolioPrimaryTokenInfo,
supportedProviders,
})
const frontendFeeTiers = frontendFees?.[aggregator] ?? ([] as const)
return swapManagerMaker({swapStorage, swapApi, frontendFeeTiers, aggregator, aggregatorTokenId})
}, [wallet.isMainnet, wallet.portfolioPrimaryTokenInfo, stakingKey, frontendFees])

return (
<SwapProvider swapManager={swapManager}>
<SwapFormProvider>
<OfflineBanner />

<Tab.Navigator
sceneContainerStyle={{backgroundColor: colors.background}}
screenOptions={{
headerShown: false,
tabBarLabelStyle: styles.labelStyle,
tabBarActiveTintColor: colors.active,
tabBarInactiveTintColor: colors.inactive,
tabBarBackground: () => (
<View style={{...StyleSheet.absoluteFillObject, backgroundColor: colors.background}} />
),
tabBarStyle: {
borderTopColor: colors.divider,
borderTopWidth: 2 * StyleSheet.hairlineWidth,

// keyboardWillShow keyboardWillHiden dont work on android
display: isKeyboardOpen ? 'none' : undefined,
},
tabBarHideOnKeyboard: true,
<SwapProvider>
<OfflineBanner />

<Tab.Navigator
sceneContainerStyle={{backgroundColor: colors.background}}
screenOptions={{
headerShown: false,
tabBarLabelStyle: styles.labelStyle,
tabBarActiveTintColor: colors.active,
tabBarInactiveTintColor: colors.inactive,
tabBarBackground: () => (
<View style={{...StyleSheet.absoluteFillObject, backgroundColor: colors.background}} />
),
tabBarStyle: {
borderTopColor: colors.divider,
borderTopWidth: 2 * StyleSheet.hairlineWidth,

// keyboardWillShow keyboardWillHiden dont work on android
display: isKeyboardOpen ? 'none' : undefined,
},
tabBarHideOnKeyboard: true,
}}
tabBar={(props) => <TabBarWithHiddenContent {...props} />}
backBehavior="initialRoute"
>
<Tab.Screen
name="history"
options={{
tabBarIcon: ({focused}) =>
focused ? (
<Icon.TabWalletActive size={24} color={colors.active} />
) : (
<Icon.TabWallet size={24} color={colors.inactive} />
),
tabBarLabel: strings.walletTabBarLabel,
tabBarTestID: 'walletTabBarButton',
}}
tabBar={(props) => <TabBarWithHiddenContent {...props} />}
backBehavior="initialRoute"
>
<Tab.Screen
name="history"
options={{
tabBarIcon: ({focused}) =>
focused ? (
<Icon.TabWalletActive size={24} color={colors.active} />
) : (
<Icon.TabWallet size={24} color={colors.inactive} />
),
tabBarLabel: strings.walletTabBarLabel,
tabBarTestID: 'walletTabBarButton',
}}
>
{() => (
<SearchProvider>
<TxHistoryNavigator />
</SearchProvider>
)}
</Tab.Screen>

<Tab.Screen
name="portfolio"
initialParams={{screen: 'dashboard-portfolio'}}
options={{
tabBarIcon: ({focused}) =>
focused ? (
<Icon.TabPortfolioActive size={24} color={colors.active} />
) : (
<Icon.TabPortfolio size={24} color={colors.inactive} />
),
tabBarLabel: strings.portfolioButton,
tabBarTestID: 'portfolioTabBarButton',
}}
>
{() => (
<SearchProvider>
<PortfolioNavigator />
</SearchProvider>
)}
</Tab.Screen>

<Tab.Screen
name="discover"
options={{
tabBarIcon: ({focused}) =>
focused ? (
<Icon.TabDiscoverActive size={28} color={colors.active} />
) : (
<Icon.TabDiscover size={28} color={colors.inactive} />
),
tabBarLabel: strings.discoverTabBarLabel,
tabBarTestID: 'discoverTabBarButton',
}}
>
{() => (
<SearchProvider>
<DiscoverNavigator />
</SearchProvider>
)}
</Tab.Screen>

<Tab.Screen
name="menu"
component={MenuNavigator}
options={{
tabBarIcon: ({focused}) =>
focused ? (
<Icon.TabMenuActive size={28} color={colors.active} />
) : (
<Icon.TabMenu size={28} color={colors.inactive} />
),
tabBarLabel: strings.menuTabBarLabel,
tabBarTestID: 'menuTabBarButton',
}}
/>
</Tab.Navigator>
</SwapFormProvider>
{() => (
<SearchProvider>
<TxHistoryNavigator />
</SearchProvider>
)}
</Tab.Screen>

<Tab.Screen
name="portfolio"
initialParams={{screen: 'dashboard-portfolio'}}
options={{
tabBarIcon: ({focused}) =>
focused ? (
<Icon.TabPortfolioActive size={24} color={colors.active} />
) : (
<Icon.TabPortfolio size={24} color={colors.inactive} />
),
tabBarLabel: strings.portfolioButton,
tabBarTestID: 'portfolioTabBarButton',
}}
>
{() => (
<SearchProvider>
<PortfolioNavigator />
</SearchProvider>
)}
</Tab.Screen>

<Tab.Screen
name="discover"
options={{
tabBarIcon: ({focused}) =>
focused ? (
<Icon.TabDiscoverActive size={28} color={colors.active} />
) : (
<Icon.TabDiscover size={28} color={colors.inactive} />
),
tabBarLabel: strings.discoverTabBarLabel,
tabBarTestID: 'discoverTabBarButton',
}}
>
{() => (
<SearchProvider>
<DiscoverNavigator />
</SearchProvider>
)}
</Tab.Screen>

<Tab.Screen
name="menu"
component={MenuNavigator}
options={{
tabBarIcon: ({focused}) =>
focused ? (
<Icon.TabMenuActive size={28} color={colors.active} />
) : (
<Icon.TabMenu size={28} color={colors.inactive} />
),
tabBarLabel: strings.menuTabBarLabel,
tabBarTestID: 'menuTabBarButton',
}}
/>
</Tab.Navigator>
</SwapProvider>
)
}
Expand Down
7 changes: 4 additions & 3 deletions apps/wallet-mobile/src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ const useStyles = ({
case ButtonType.Link:
shape =
size === 'M'
? {...atoms.p_md, ...atoms.gap_xs, ...atoms.rounded_sm}
: {...atoms.p_sm, ...atoms.gap_2xs, ...atoms.rounded_sm}
? {maxHeight: 40, ...atoms.py_sm, ...atoms.px_md, ...atoms.gap_xs, ...atoms.rounded_sm}
: {maxHeight: 32, ...atoms.p_xs, ...atoms.px_sm, ...atoms.gap_2xs, ...atoms.rounded_sm}
break
case ButtonType.Circle:
shape = {width: 56, height: 56, ...atoms.align_center, ...atoms.rounded_full}
Expand Down Expand Up @@ -182,7 +182,8 @@ const useStyles = ({
})

const iconProps: IconProps = {
size: size === 'M' ? 28 : 24,
size:
type === ButtonType.Text || type === ButtonType.SecondaryText ? (size === 'M' ? 24 : 20) : size === 'M' ? 28 : 24,
color: foregroundColor,
}

Expand Down
Loading
Loading