Skip to content

Commit

Permalink
feat(swap): add complete order integration (#2742)
Browse files Browse the repository at this point in the history
Signed-off-by: Sorin Chis <[email protected]>
Co-authored-by: Juliano Lazzarotto <[email protected]>
Co-authored-by: jorbuedo <[email protected]>
Co-authored-by: Ruslan Dudin <[email protected]>
Co-authored-by: Michal <[email protected]>
  • Loading branch information
5 people authored Oct 11, 2023
1 parent 8967f20 commit 5b5872d
Show file tree
Hide file tree
Showing 17 changed files with 688 additions and 554 deletions.
14 changes: 4 additions & 10 deletions apps/wallet-mobile/src/TxHistory/TxDetails/TxDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {BigNumber} from 'bignumber.js'
import {fromPairs} from 'lodash'
import React, {useEffect, useState} from 'react'
import {defineMessages, IntlShape, useIntl} from 'react-intl'
import {LayoutAnimation, Linking, StyleSheet, TouchableOpacity, View, ViewProps} from 'react-native'
import {LayoutAnimation, StyleSheet, TouchableOpacity, View, ViewProps} from 'react-native'
import {ScrollView} from 'react-native-gesture-handler'

import {Banner, Boundary, Button, CopyButton, FadeIn, Icon, StatusBar, Text} from '../../components'
Expand All @@ -17,11 +17,10 @@ import {useSelectedWallet} from '../../SelectedWallet'
import {brand, COLORS} from '../../theme'
import {isEmptyString} from '../../utils/utils'
import {MultiToken} from '../../yoroi-wallets/cardano/MultiToken'
import {getNetworkConfigById} from '../../yoroi-wallets/cardano/networks'
import {CardanoTypes, YoroiWallet} from '../../yoroi-wallets/cardano/types'
import {useTipStatus, useTransactionInfos} from '../../yoroi-wallets/hooks'
import {NetworkId, TransactionInfo} from '../../yoroi-wallets/types'
import {asQuantity} from '../../yoroi-wallets/utils'
import {TransactionInfo} from '../../yoroi-wallets/types'
import {asQuantity, openInExplorer} from '../../yoroi-wallets/utils'
import {AssetList} from './AssetList'
import assetListStyle from './AssetListTransaction.style'

Expand Down Expand Up @@ -168,7 +167,7 @@ export const TxDetails = () => {

<Actions>
<Button
onPress={() => openInExplorer(transaction, wallet.networkId)}
onPress={() => openInExplorer(transaction.id, wallet.networkId)}
title={strings.openInExplorer}
shelleyTheme
/>
Expand Down Expand Up @@ -324,11 +323,6 @@ const getShownAddresses = (
}
}

const openInExplorer = async (transaction: TransactionInfo, networkId: NetworkId) => {
const networkConfig = getNetworkConfigById(networkId)
await Linking.openURL(networkConfig.EXPLORER_URL_FOR_TX(transaction.id))
}

export type Params = {
id: string
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,13 @@ export const HiddenInfoWrapper = ({
info,
onPress,
value,
icon,
}: {
label: string
info?: React.ReactNode
onPress?: () => void
value: React.ReactNode
icon?: React.ReactNode
}) => {
return (
<View>
Expand All @@ -116,7 +118,21 @@ export const HiddenInfoWrapper = ({
)}
</View>

{isString(value) ? <Text style={styles.text}>{value}</Text> : value}
{isString(value) ? (
<View style={styles.flex}>
{icon !== undefined && (
<View style={styles.flex}>
{icon}

<Spacer width={6} />
</View>
)}

<Text style={styles.text}>{value}</Text>
</View>
) : (
value
)}
</View>

<Spacer height={8} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@ import {COLORS} from '../../../../theme'
import {WrongPassword} from '../../../../yoroi-wallets/cardano/errors'
import {useStrings} from '../../common/strings'

export type ErrorData = {
errorMessage: string
errorLogs?: unknown
}

type Props = {
onSubmit?: (spendingPassword: string) => void
isLoading?: boolean
error?: Error
onPasswordChange?: () => void
}

export const ConfirmWithSpendingPassword = ({onSubmit, isLoading, error}: Props) => {
export const ConfirmWithSpendingPassword = ({onSubmit, isLoading, error, onPasswordChange}: Props) => {
const spendingPasswordRef = React.useRef<RNTextInput>(null)
const [spendingPassword, setSpendingPassword] = React.useState(
features.prefillWalletInfo ? debugWalletInfo.PASSWORD : '',
Expand All @@ -30,7 +36,10 @@ export const ConfirmWithSpendingPassword = ({onSubmit, isLoading, error}: Props)
enablesReturnKeyAutomatically
placeholder={strings.spendingPassword}
value={spendingPassword}
onChangeText={setSpendingPassword}
onChangeText={(text) => {
setSpendingPassword(text)
onPasswordChange && onPasswordChange()
}}
autoComplete="off"
/>

Expand All @@ -44,7 +53,13 @@ export const ConfirmWithSpendingPassword = ({onSubmit, isLoading, error}: Props)

<Spacer fill />

<Button testID="swapButton" shelleyTheme title={strings.sign} onPress={() => onSubmit?.(spendingPassword)} />
<Button
testID="swapButton"
shelleyTheme
title={strings.sign}
onPress={() => onSubmit?.(spendingPassword)}
disabled={spendingPassword.length === 0}
/>

{isLoading && (
<View style={styles.loading}>
Expand Down
5 changes: 5 additions & 0 deletions apps/wallet-mobile/src/features/Swap/common/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const useStrings = () => {
swapTitle: intl.formatMessage(messages.swapTitle),
tokenSwap: intl.formatMessage(messages.tokenSwap),
orderSwap: intl.formatMessage(messages.orderSwap),
dex: intl.formatMessage(messages.dex),
marketButton: intl.formatMessage(messages.marketButton),
limitButton: intl.formatMessage(messages.limitButton),
swapFrom: intl.formatMessage(messages.swapFrom),
Expand Down Expand Up @@ -325,6 +326,10 @@ export const messages = defineMessages({
id: 'swap.swapScreen.transactionDisplay',
defaultMessage: '!!!Your transactions will be displayed both in the list of transaction and Open swap orders',
},
dex: {
id: 'swap.swapScreen.dex',
defaultMessage: '!!! dex',
},
seeOnExplorer: {
id: 'swap.swapScreen.seeOnExplorer',
defaultMessage: '!!!see on explorer',
Expand Down
2 changes: 0 additions & 2 deletions apps/wallet-mobile/src/features/Swap/common/useSwapTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ export const useSwapTx = (options?: UseMutationOptions<YoroiUnsignedTx, Error, {
sellQuantity: orderData.amounts.sell.quantity,
buyTokenId: orderData.amounts.buy.tokenId,
buyQuantity: orderData.amounts.buy.quantity,
depositFee: pool?.deposit.quantity,
feeTokenId: pool?.deposit.tokenId,
poolId: pool?.poolId,
}),
),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@ import {YoroiWallet} from '../../../../yoroi-wallets/cardano/types'
import {useSignWithPasswordAndSubmitTx} from '../../../../yoroi-wallets/hooks'
import {YoroiUnsignedTx} from '../../../../yoroi-wallets/types'
import {ConfirmWithSpendingPassword} from '../../common/ConfirmWithSpendingPassword'
import {ErrorData} from '../../common/ConfirmWithSpendingPassword/ConfirmWithSpendingPassword'
import {useStrings} from '../../common/strings'

type ErrorData = {
errorMessage: string
errorLogs?: unknown
}

type Props = {
wallet: YoroiWallet
unsignedTx: YoroiUnsignedTx
Expand Down Expand Up @@ -64,6 +60,7 @@ export const ConfirmTxWithPassword = ({wallet, onSuccess, unsignedTx}: Props) =>
onSubmit={onConfirm}
isLoading={isLoading}
error={errorData.errorMessage.length > 0 ? new Error(errorData.errorMessage) : undefined}
onPasswordChange={() => setErrorData({errorMessage: '', errorLogs: ''})}
/>
)
}
Loading

0 comments on commit 5b5872d

Please sign in to comment.