Skip to content

Commit

Permalink
feat(swap): integrate muesliswap api (#2528)
Browse files Browse the repository at this point in the history
Signed-off-by: Juliano Lazzarotto <30806844+stackchain@users.noreply.github.com>
Co-authored-by: Ahmed Ibrahim <me@ahmedibrahim.dev>
  • Loading branch information
stackchain and neuodev authored Jul 27, 2023
1 parent 06ceeb1 commit d57eb12
Show file tree
Hide file tree
Showing 103 changed files with 2,549 additions and 1,599 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,5 @@ coverage/

# .vscode
**/extensions.json

apps/test/
1 change: 1 addition & 0 deletions apps/wallet-mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@
"@wdio/mocha-framework": "^7.16.6",
"@wdio/selenium-standalone-service": "^7.25.1",
"@wdio/spec-reporter": "^7.16.4",
"@yoroi/types": "1.0.4",
"babel-eslint": "^10.1.0",
"babel-jest": "^29.2.1",
"babel-loader": "8.2.2",
Expand Down
7 changes: 5 additions & 2 deletions apps/wallet-mobile/src/Catalyst/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import {Balance} from '@yoroi/types'
import {useEffect, useState} from 'react'

import {YoroiWallet} from '../yoroi-wallets/cardano/types'
import {CATALYST, isHaskellShelley} from '../yoroi-wallets/cardano/utils'
import {useBalances} from '../yoroi-wallets/hooks'
import {Quantity} from '../yoroi-wallets/types/yoroi'
import {Amounts, Quantities} from '../yoroi-wallets/utils'

export const useCanVote = (wallet: YoroiWallet) => {
const balances = useBalances(wallet)
const primaryAmount = Amounts.getAmount(balances, '')
const sufficientFunds = Quantities.isGreaterThan(primaryAmount.quantity, CATALYST.MIN_ADA.toString() as Quantity)
const sufficientFunds = Quantities.isGreaterThan(
primaryAmount.quantity,
CATALYST.MIN_ADA.toString() as Balance.Quantity,
)

return {
canVote: !wallet.isReadOnly && isHaskellShelley(wallet.walletImplementationId),
Expand Down
7 changes: 4 additions & 3 deletions apps/wallet-mobile/src/Dashboard/StakePoolInfos.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {Balance} from '@yoroi/types'
import BigNumber from 'bignumber.js'
import React from 'react'
import {ActivityIndicator, StyleSheet, View} from 'react-native'
import {useQuery, useQueryClient, UseQueryOptions} from 'react-query'

import {useSelectedWallet} from '../SelectedWallet'
import {YoroiWallet} from '../yoroi-wallets/cardano/types'
import {Quantity, StakingInfo, YoroiUnsignedTx} from '../yoroi-wallets/types'
import {StakingInfo, YoroiUnsignedTx} from '../yoroi-wallets/types'
import {Quantities} from '../yoroi-wallets/utils'
import {StakePoolInfo} from './StakePoolInfo'

Expand Down Expand Up @@ -93,8 +94,8 @@ export const useStakingTx = (

const stakingUtxos = await wallet.getAllUtxosForKey()
const amountToDelegate = Quantities.sum([
...stakingUtxos.map((utxo) => utxo.amount as Quantity),
accountState.remainingAmount as Quantity,
...stakingUtxos.map((utxo) => utxo.amount as Balance.Quantity),
accountState.remainingAmount as Balance.Quantity,
])

return wallet.createDelegationTx(poolId, new BigNumber(amountToDelegate))
Expand Down
10 changes: 5 additions & 5 deletions apps/wallet-mobile/src/NftDetails/NftDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {RouteProp, useRoute} from '@react-navigation/native'
import {Balance} from '@yoroi/types'
import React, {ReactNode, useState} from 'react'
import {defineMessages, useIntl} from 'react-intl'
import {Dimensions, Linking, StyleSheet, TouchableOpacity, View} from 'react-native'
Expand All @@ -16,7 +17,6 @@ import {useSelectedWallet} from '../SelectedWallet'
import {COLORS} from '../theme'
import {getNetworkConfigById} from '../yoroi-wallets/cardano/networks'
import {useNft} from '../yoroi-wallets/hooks'
import {TokenInfo} from '../yoroi-wallets/types'
import {isRecord, isString} from '../yoroi-wallets/utils'

export const NftDetails = () => {
Expand Down Expand Up @@ -68,7 +68,7 @@ export const NftDetails = () => {
)
}

const UnModeratedNftImage = ({nft}: {nft: TokenInfo}) => {
const UnModeratedNftImage = ({nft}: {nft: Balance.TokenInfo}) => {
const navigateTo = useNavigateTo()
return (
<TouchableOpacity onPress={() => navigateTo.nftZoom(nft.id)} style={styles.imageWrapper}>
Expand All @@ -77,7 +77,7 @@ const UnModeratedNftImage = ({nft}: {nft: TokenInfo}) => {
)
}

const ModeratedNftImage = ({nft}: {nft: TokenInfo}) => {
const ModeratedNftImage = ({nft}: {nft: Balance.TokenInfo}) => {
const wallet = useSelectedWallet()
const navigateTo = useNavigateTo()
const {status} = useModeratedNftImage({wallet, fingerprint: nft.fingerprint})
Expand Down Expand Up @@ -114,7 +114,7 @@ const MetadataRow = ({title, copyText, children}: {title: string; children: Reac
)
}

const NftOverview = ({nft}: {nft: TokenInfo}) => {
const NftOverview = ({nft}: {nft: Balance.TokenInfo}) => {
const strings = useStrings()
const wallet = useSelectedWallet()
const config = getNetworkConfigById(wallet.networkId)
Expand Down Expand Up @@ -195,7 +195,7 @@ const HR = () => (
/>
)

const NftMetadata = ({nft}: {nft: TokenInfo}) => {
const NftMetadata = ({nft}: {nft: Balance.TokenInfo}) => {
const strings = useStrings()
const stringifiedMetadata = JSON.stringify(nft.metadatas.mintNft, undefined, 2)

Expand Down
4 changes: 2 additions & 2 deletions apps/wallet-mobile/src/Nfts/Nfts.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {Balance} from '@yoroi/types'
import React, {ReactNode} from 'react'
import {defineMessages, useIntl} from 'react-intl'
import {RefreshControl, ScrollView, StyleSheet, Text, View} from 'react-native'
Expand All @@ -8,7 +9,6 @@ import {useMetrics} from '../metrics/metricsManager'
import {useSearch, useSearchOnNavBar} from '../Search/SearchContext'
import {useSelectedWallet} from '../SelectedWallet'
import {useNfts} from '../yoroi-wallets/hooks'
import {TokenInfo} from '../yoroi-wallets/types'
import {filterNfts, useTrackNftGallerySearchActivated} from './filterNfts'
import {useNavigateTo} from './navigation'
import {NoNftsScreen} from './NoNftsScreen'
Expand Down Expand Up @@ -195,7 +195,7 @@ const LoadingScreen = ({nftsCount}: {nftsCount: number}) => {
)
}

const byName = ({name: A}: TokenInfo, {name: B}: TokenInfo) => A.localeCompare(B)
const byName = ({name: A}: Balance.TokenInfo, {name: B}: Balance.TokenInfo) => A.localeCompare(B)

const styles = StyleSheet.create({
safeAreaView: {
Expand Down
5 changes: 3 additions & 2 deletions apps/wallet-mobile/src/Nfts/filterNfts.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import {Balance} from '@yoroi/types'

import {nft} from '../yoroi-wallets/mocks'
import {TokenInfo} from '../yoroi-wallets/types'
import {filterNfts} from './filterNfts'

describe('filterNfts', () => {
const cryptoWolf = {...nft, id: '0', fingerprint: 'fakefingerprint1', name: 'CryptoWolf #1234'}
const boredMonkey = {...nft, id: '1', fingerprint: 'fakefingerprint2', name: 'Bored Monkey #4567'}
const appleBlocks = {...nft, id: '2', fingerprint: 'fakefingerprint3', name: 'Apple Blocks #7890'}

const nfts: TokenInfo[] = [cryptoWolf, boredMonkey, appleBlocks]
const nfts: Balance.TokenInfo[] = [cryptoWolf, boredMonkey, appleBlocks]

it('filters NFTs correctly with case-insensitive search term', () => {
const filteredNfts = filterNfts('APple bLOcks', nfts)
Expand Down
4 changes: 2 additions & 2 deletions apps/wallet-mobile/src/Nfts/filterNfts.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {Balance} from '@yoroi/types'
import React from 'react'

import {useMetrics} from '../metrics/metricsManager'
import {TokenInfo} from '../yoroi-wallets/types'

export const filterNfts = (searchTerm: string, nfts: TokenInfo[]): TokenInfo[] => {
export const filterNfts = (searchTerm: string, nfts: Balance.TokenInfo[]): Balance.TokenInfo[] => {
const searchTermLowerCase = searchTerm.toLowerCase()
const filteredNfts =
searchTermLowerCase.length > 0 ? nfts.filter((nft) => nft.name?.toLowerCase().includes(searchTermLowerCase)) : nfts
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import {Balance} from '@yoroi/types'
import React, {useEffect, useState} from 'react'
import {defineMessages, useIntl} from 'react-intl'
import {ScrollView, StyleSheet, View, ViewProps} from 'react-native'
Expand All @@ -15,7 +16,6 @@ import {useSelectedWallet} from '../../SelectedWallet'
import {COLORS} from '../../theme'
import {NETWORKS} from '../../yoroi-wallets/cardano/networks'
import {NUMBERS} from '../../yoroi-wallets/cardano/numbers'
import {Quantity} from '../../yoroi-wallets/types'
import {Amounts, Entries, Quantities} from '../../yoroi-wallets/utils'

type Params = StakingCenterRoutes['delegation-confirmation']
Expand Down Expand Up @@ -167,10 +167,10 @@ const messages = defineMessages({
* TODO: based on https://staking.cardano.org/en/calculator/
* needs to be update per-network
*/
const approximateReward = (stakedQuantity: Quantity): Quantity => {
const approximateReward = (stakedQuantity: Balance.Quantity): Balance.Quantity => {
return Quantities.quotient(
Quantities.product([stakedQuantity, `${NETWORKS.HASKELL_SHELLEY.PER_EPOCH_PERCENTAGE_REWARD}`]),
NUMBERS.EPOCH_REWARD_DENOMINATOR.toString() as Quantity,
NUMBERS.EPOCH_REWARD_DENOMINATOR.toString() as Balance.Quantity,
)
}

Expand Down
4 changes: 2 additions & 2 deletions apps/wallet-mobile/src/TxHistory/AssetList/AssetList.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {FlashList, FlashListProps} from '@shopify/flash-list'
import {Balance} from '@yoroi/types'
import React from 'react'
import {defineMessages, useIntl} from 'react-intl'
import {Alert, Linking, StyleSheet, TouchableOpacity, View} from 'react-native'
Expand All @@ -11,11 +12,10 @@ import {usePrivacyMode} from '../../Settings/PrivacyMode/PrivacyMode'
import {sortTokenInfos} from '../../utils'
import {getNetworkConfigById} from '../../yoroi-wallets/cardano/networks'
import {useBalances, useTokenInfos} from '../../yoroi-wallets/hooks'
import {TokenInfo} from '../../yoroi-wallets/types'
import {Amounts} from '../../yoroi-wallets/utils'
import {ActionsBanner} from './ActionsBanner'

type ListProps = FlashListProps<TokenInfo>
type ListProps = FlashListProps<Balance.TokenInfo>
type Props = Partial<ListProps> & {
onScroll: ListProps['onScroll']
refreshing: boolean
Expand Down
9 changes: 5 additions & 4 deletions apps/wallet-mobile/src/TxHistory/PairedBalance.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {Balance} from '@yoroi/types'
import * as React from 'react'
import {defineMessages, useIntl} from 'react-intl'
import {StyleSheet, Text} from 'react-native'
Expand All @@ -8,12 +9,12 @@ import {useSelectedWallet} from '../SelectedWallet'
import {useCurrencyContext} from '../Settings/Currency'
import {COLORS} from '../theme'
import {useExchangeRate} from '../yoroi-wallets/hooks'
import {CurrencySymbol, YoroiAmount} from '../yoroi-wallets/types'
import {CurrencySymbol} from '../yoroi-wallets/types'
import {Quantities} from '../yoroi-wallets/utils'

type Props = {
privacyMode?: PrivacyMode
amount: YoroiAmount
amount: Balance.Amount
}
export const PairedBalance = React.forwardRef<ResetErrorRef, Props>(({privacyMode, amount}, ref) => {
const {currency} = useCurrencyContext()
Expand All @@ -30,13 +31,13 @@ export const PairedBalance = React.forwardRef<ResetErrorRef, Props>(({privacyMod
),
}}
>
<Balance privacyMode={privacyMode} amount={amount} />
<PairedAmount privacyMode={privacyMode} amount={amount} />
</Boundary>
)
})

const hiddenPairedTotal = '*.**'
const Balance = ({privacyMode, amount}: Props) => {
const PairedAmount = ({privacyMode, amount}: Props) => {
const wallet = useSelectedWallet()
const {currency, config} = useCurrencyContext()
const rate = useExchangeRate({wallet, to: currency})
Expand Down
4 changes: 2 additions & 2 deletions apps/wallet-mobile/src/components/AmountItem/AmountItem.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {Balance} from '@yoroi/types'
import * as React from 'react'
import {StyleSheet, View, ViewProps} from 'react-native'

Expand All @@ -7,13 +8,12 @@ import {PairedBalance} from '../../TxHistory/PairedBalance'
import {isEmptyString} from '../../utils'
import {YoroiWallet} from '../../yoroi-wallets/cardano/types'
import {useTokenInfo} from '../../yoroi-wallets/hooks'
import {YoroiAmount} from '../../yoroi-wallets/types'
import {Quantities} from '../../yoroi-wallets/utils'
import {Boundary, Placeholder, Text, TokenIcon} from '..'

export type AmountItemProps = {
wallet: YoroiWallet
amount: YoroiAmount
amount: Balance.Amount
style?: ViewProps['style']
privacyMode?: PrivacyMode
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {FlashList, FlashListProps} from '@shopify/flash-list'
import {Balance} from '@yoroi/types'
import React from 'react'
import {Dimensions, StyleSheet, TouchableOpacity, TouchableOpacityProps, View} from 'react-native'
import SkeletonPlaceholder from 'react-native-skeleton-placeholder'

import {features} from '../../features'
import {useModeratedNftImage} from '../../Nfts/hooks'
import {useSelectedWallet} from '../../SelectedWallet/Context'
import {TokenInfo} from '../../yoroi-wallets/types'
import {Icon} from '../Icon'
import {NftPreview} from '../NftPreview'
import {Spacer} from '../Spacer'
Expand All @@ -21,12 +21,12 @@ export const SkeletonGallery = ({amount}: {amount: number}) => {
}

type Props = {
nfts: TokenInfo[]
nfts: Balance.TokenInfo[]
onSelect: (id: string) => void
onRefresh: () => void
isRefreshing: boolean
bounces?: FlashListProps<TokenInfo>['bounces']
ListEmptyComponent?: FlashListProps<TokenInfo>['ListEmptyComponent']
bounces?: FlashListProps<Balance.TokenInfo>['bounces']
ListEmptyComponent?: FlashListProps<Balance.TokenInfo>['ListEmptyComponent']
withVerticalPadding?: boolean
readOnly?: boolean
}
Expand Down Expand Up @@ -60,7 +60,7 @@ export const NftImageGallery = ({
}

type ModeratedImageProps = TouchableOpacityProps & {
nft: TokenInfo
nft: Balance.TokenInfo
}
const UnModeratedImage = ({nft, ...props}: ModeratedImageProps) => {
return (
Expand Down Expand Up @@ -112,11 +112,11 @@ const ModeratedImage = ({nft, ...props}: ModeratedImageProps) => {
)
}

function BlockedNft({nft}: {nft: TokenInfo}) {
function BlockedNft({nft}: {nft: Balance.TokenInfo}) {
return <PlaceholderNft nft={nft} />
}

function PlaceholderNft({nft}: {nft: TokenInfo}) {
function PlaceholderNft({nft}: {nft: Balance.TokenInfo}) {
return (
<View>
<View style={styles.imageWrapper}>
Expand All @@ -137,11 +137,11 @@ function PlaceholderNft({nft}: {nft: TokenInfo}) {
)
}

function ManualReviewNft({nft}: {nft: TokenInfo}) {
function ManualReviewNft({nft}: {nft: Balance.TokenInfo}) {
return <PlaceholderNft nft={nft} />
}

function RequiresConsentNft({nft}: {nft: TokenInfo}) {
function RequiresConsentNft({nft}: {nft: Balance.TokenInfo}) {
return (
<View>
<View style={styles.imageWrapper}>
Expand All @@ -166,7 +166,7 @@ function RequiresConsentNft({nft}: {nft: TokenInfo}) {
)
}

function ApprovedNft({nft}: {nft: TokenInfo}) {
function ApprovedNft({nft}: {nft: Balance.TokenInfo}) {
return (
<View>
<View style={styles.imageWrapper}>
Expand Down
4 changes: 2 additions & 2 deletions apps/wallet-mobile/src/components/NftPreview/NftPreview.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {Balance} from '@yoroi/types'
import React, {useEffect, useState} from 'react'
import {ErrorBoundary} from 'react-error-boundary'
import {Image, ImageResizeMode, ImageStyle, StyleProp, View} from 'react-native'
Expand All @@ -6,7 +7,6 @@ import {SvgUri} from 'react-native-svg'

import placeholder from '../../assets/img/nft-placeholder.png'
import {getNftFilenameMediaType, getNftMainImageMediaType, isSvgMediaType} from '../../yoroi-wallets/cardano/nfts'
import {TokenInfo} from '../../yoroi-wallets/types'
import {isString} from '../../yoroi-wallets/utils'

export const NftPreview = ({
Expand All @@ -19,7 +19,7 @@ export const NftPreview = ({
resizeMode,
blurRadius,
}: {
nft: TokenInfo
nft: Balance.TokenInfo
showPlaceholder?: boolean
style?: StyleProp<ImageStyle>
showThumbnail?: boolean
Expand Down
Loading

0 comments on commit d57eb12

Please sign in to comment.