Skip to content

Commit

Permalink
chore: add sign and submit with passwoard (#2663)
Browse files Browse the repository at this point in the history
  • Loading branch information
stackchain authored Sep 15, 2023
2 parents 5abac9a + 9cbce1e commit 8cd4494
Show file tree
Hide file tree
Showing 35 changed files with 1,380 additions and 681 deletions.
3 changes: 2 additions & 1 deletion apps/wallet-mobile/.storybook/storybook.requires.js

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

8 changes: 4 additions & 4 deletions apps/wallet-mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@
"@cardano-foundation/ledgerjs-hw-app-cardano": "^6.0.0",
"@emurgo/cip14-js": "^3.0.1",
"@emurgo/cip4-js": "1.0.7",
"@emurgo/cross-csl-core": "^2.6.0",
"@emurgo/cross-csl-mobile": "^2.6.0",
"@emurgo/cross-csl-core": "^2.7.0",
"@emurgo/cross-csl-mobile": "^2.7.0",
"@emurgo/csl-mobile-bridge": "^5.1.2",
"@emurgo/react-native-blockies-svg": "^0.0.2",
"@emurgo/react-native-hid": "^5.15.6",
"@emurgo/yoroi-lib": "^0.7.0",
"@emurgo/yoroi-lib": "^0.8.0",
"@formatjs/intl-datetimeformat": "^6.7.0",
"@formatjs/intl-getcanonicallocales": "^2.1.0",
"@formatjs/intl-locale": "^3.2.1",
Expand Down Expand Up @@ -205,7 +205,7 @@
"@babel/runtime": "^7.20.0",
"@config-plugins/detox": "^5.0.1",
"@emurgo/cardano-serialization-lib-nodejs": "^9.1.4",
"@emurgo/cross-csl-nodejs": "^2.6.0",
"@emurgo/cross-csl-nodejs": "^2.7.0",
"@formatjs/cli": "^6.1.0",
"@formatjs/ts-transformer": "^3.13.0",
"@react-navigation/devtools": "^6.0.13",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type Props = {
onSelectBLE: () => void
}

const useIsUsbSupported = () => {
export const useIsUsbSupported = () => {
const [isUSBSupported, setUSBSupported] = React.useState(false)
React.useEffect(() => {
DeviceInfo.getApiLevel().then((sdk) =>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {storiesOf} from '@storybook/react-native'
import React from 'react'
import {StyleSheet, View} from 'react-native'

import {TransactionSigned} from './TransactionSigned'

const styles = StyleSheet.create({
container: {
flex: 1,
padding: 16,
},
})

storiesOf('SWAP TransactionSigned', module) //
.add('success', () => {
return (
<View style={styles.container}>
<TransactionSigned />
</View>
)
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import React from 'react'
import {Image, StyleSheet, Text, TouchableOpacity, View} from 'react-native'

import TxSuccess from '../../../../assets/img//transaction-success.png'
import {Button} from '../../../../components'
import {useNavigateTo} from '../navigation'
import {useStrings} from '../strings'

export const TransactionSigned = () => {
const strings = useStrings()
const navigate = useNavigateTo()

return (
<View style={styles.container}>
<View>
<Image source={TxSuccess} />
</View>

<Text style={styles.title}>{strings.transactionSigned}</Text>

<Text style={styles.text}>{strings.transactionDisplay}</Text>

<TouchableOpacity style={styles.button}>
<Text>{strings.seeOnExplorer}</Text>
</TouchableOpacity>

<Button shelleyTheme title={strings.goToOrders} onPress={() => navigate.startSwap()} />
</View>
)
}

const styles = StyleSheet.create({
container: {
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
height: '100%',
},
title: {
fontWeight: '500',
fontSize: 20,
paddingBottom: 4,
},
text: {
color: '#6B7384',
fontSize: 16,
},
button: {
paddingVertical: 16,
},
})
12 changes: 9 additions & 3 deletions apps/wallet-mobile/src/features/Swap/common/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {Swap} from '@yoroi/types'
import {BalanceQuantity} from '@yoroi/types/lib/balance/token'
import BigNumber from 'bignumber.js'

import {YoroiWallet} from '../../../yoroi-wallets/cardano/types'
import {YoroiEntry} from '../../../yoroi-wallets/types'
import {Quantities} from '../../../yoroi-wallets/utils'

Expand Down Expand Up @@ -35,21 +36,26 @@ export const getSellQuantityForLimitOrder = (
).toString() as BalanceQuantity
}

export const createYoroiEntry = (createOrder: Swap.CreateOrderData, address: string): YoroiEntry => {
export const createYoroiEntry = (
createOrder: Swap.CreateOrderData,
address: string,
wallet: YoroiWallet,
): YoroiEntry => {
const amountEntry = {}

const tokenId = createOrder?.amounts?.sell.tokenId
if (tokenId != null && createOrder.amounts.sell.quantity !== undefined) {
if (createOrder?.amounts?.sell.tokenId === '') {
if (tokenId === wallet.primaryTokenInfo.id) {
amountEntry[tokenId] = Quantities.sum([
createOrder.selectedPool.deposit.quantity,
createOrder.selectedPool.batcherFee.quantity,
createOrder.amounts.sell.quantity,
])
} else {
amountEntry[''] = createOrder.selectedPool.deposit.quantity
amountEntry[tokenId] = createOrder.amounts.sell.quantity
}
}

return {
address: address,
amounts: amountEntry,
Expand Down
47 changes: 47 additions & 0 deletions apps/wallet-mobile/src/features/Swap/common/mocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import {mockSwapStateDefault} from '@yoroi/swap'

import {mocks as walletMocks} from '../../../yoroi-wallets/mocks/wallet'
import {asQuantity} from '../../../yoroi-wallets/utils'

type ProviderType = 'sundaeswap' | 'minswap' | 'wingriders' | 'muesliswap_v1' | 'muesliswap_v2' | 'muesliswap_v3'
type Type = 'market' | 'limit'

export const mocks = {
confirmTx: {
...mockSwapStateDefault,
yoroiUnsignedTx: walletMocks.yoroiUnsignedTx,
createOrder: {
address: '',
amounts: {
buy: {
quantity: asQuantity(20467572) as `${number}`,
tokenId: '208a2ca888886921513cb777bb832a8dc685c04de990480151f12150.53484942414441',
},
sell: {quantity: asQuantity(2000000), tokenId: ''},
},
datum: '',
datumHash: '',
limitPrice: undefined,
selectedPool: {
batcherFee: {quantity: asQuantity(2500000), tokenId: ''},
deposit: {quantity: asQuantity(2000000), tokenId: ''},
fee: '0.05',
lastUpdate: '2023-09-08 09:56:13',
lpToken: {
quantity: asQuantity(68917682),
tokenId: '0029cb7c88c7567b63d1a512c0ed626aa169688ec980730c0473b913.6c702083',
},
poolId: '0029cb7c88c7567b63d1a512c0ed626aa169688ec980730c0473b913.702083',
price: 0.0890390378168252,
provider: 'sundaeswap' as ProviderType,
tokenA: {quantity: asQuantity(20630071), tokenId: ''},
tokenB: {
quantity: asQuantity(231696922),
tokenId: '208a2ca888886921513cb777bb832a8dc685c04de990480151f12150.53484942414441',
},
},
slippage: 1,
type: 'market' as Type,
},
},
}
58 changes: 58 additions & 0 deletions apps/wallet-mobile/src/features/Swap/common/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const useStrings = () => {
sign: intl.formatMessage(messages.sign),
searchTokens: intl.formatMessage(messages.searchTokens),
confirm: intl.formatMessage(messages.confirm),
chooseConnectionMethod: intl.formatMessage(messages.chooseConnectionMethod),
selecteAssetTitle: intl.formatMessage(messages.selectAssetTitle),
tokens: (qty: number) => intl.formatMessage(globalMessages.tokens, {qty}),
apply: intl.formatMessage(globalMessages.apply),
Expand Down Expand Up @@ -85,6 +86,17 @@ export const useStrings = () => {
limitPriceWarningMarketPrice: intl.formatMessage(messages.limitPriceWarningMarketPrice),
limitPriceWarningBack: intl.formatMessage(messages.limitPriceWarningBack),
limitPriceWarningConfirm: intl.formatMessage(messages.limitPriceWarningConfirm),
error: intl.formatMessage(globalMessages.error),
usbExplanation: intl.formatMessage(messages.usbExplanation),
usbButton: intl.formatMessage(messages.usbButton),
usbConnectionIsBlocked: intl.formatMessage(messages.usbConnectionIsBlocked),
bluetoothExplanation: intl.formatMessage(messages.bluetoothExplanation),
bluetoothButton: intl.formatMessage(messages.bluetoothButton),
bluetoothError: intl.formatMessage(messages.bluetoothError),
transactionSigned: intl.formatMessage(messages.transactionSigned),
transactionDisplay: intl.formatMessage(messages.transactionDisplay),
seeOnExplorer: intl.formatMessage(messages.seeOnExplorer),
goToOrders: intl.formatMessage(messages.goToOrders),
}
}

Expand Down Expand Up @@ -279,6 +291,22 @@ export const messages = defineMessages({
id: 'swap.swapScreen.limitPriceWarningConfirm',
defaultMessage: '!!!Swap',
},
transactionSigned: {
id: 'swap.swapScreen.transactionSigned',
defaultMessage: '!!!Transaction signed',
},
transactionDisplay: {
id: 'swap.swapScreen.transactionDisplay',
defaultMessage: '!!!Your transactions will be displayed both in the list of transaction and Open swap orders',
},
seeOnExplorer: {
id: 'swap.swapScreen.seeOnExplorer',
defaultMessage: '!!!see on explorer',
},
goToOrders: {
id: 'swap.swapScreen.goToOrders',
defaultMessage: '!!!GO to Orders',
},
asset: {
id: 'global.assets.assetLabel',
defaultMessage: '!!!Asset',
Expand Down Expand Up @@ -371,6 +399,36 @@ export const messages = defineMessages({
id: 'swap.listOrders.txId',
defaultMessage: '!!!Transaction ID',
},
chooseConnectionMethod: {
id: 'components.ledger.ledgertransportswitchmodal.title',
defaultMessage: '!!!Choose Connection Method',
},
usbExplanation: {
id: 'components.ledger.ledgertransportswitchmodal.usbExplanation',
defaultMessage:
'!!!Choose this option if you want to connect to a Ledger Nano model X ' +
'or S using an on-the-go USB cable adaptor:',
},
usbButton: {
id: 'components.ledger.ledgertransportswitchmodal.usbButton',
defaultMessage: '!!!Connect with USB',
},
usbConnectionIsBlocked: {
id: 'components.ledger.ledgertransportswitchmodal.usbConnectionIsBlocked',
defaultMessage: '!!! USB connection is blocked by iOS devices',
},
bluetoothExplanation: {
id: 'components.ledger.ledgertransportswitchmodal.bluetoothExplanation',
defaultMessage: '!!!Choose this option if you want to connect to a Ledger Nano model X through Bluetooth:',
},
bluetoothButton: {
id: 'components.ledger.ledgertransportswitchmodal.bluetoothButton',
defaultMessage: '!!!Connect with Bluetooth',
},
bluetoothError: {
id: 'global.ledgerMessages.bluetoothDisabledError',
defaultMessage: '!!!Connect with Bluetooth',
},
// TODO check this and change if necessary

youHave: {
Expand Down
11 changes: 6 additions & 5 deletions apps/wallet-mobile/src/features/Swap/common/useSwapTx.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import {Datum} from '@emurgo/yoroi-lib'
import {useSwap} from '@yoroi/swap'
import {UseMutationOptions} from 'react-query'

import {useSelectedWallet} from '../../../SelectedWallet'
import {useMutationWithInvalidations} from '../../../yoroi-wallets/hooks'
import {YoroiEntry, YoroiUnsignedTx} from '../../../yoroi-wallets/types'

export const useSwapTx = (
options?: UseMutationOptions<YoroiUnsignedTx, Error, {entry: YoroiEntry; datum: {hash: string}}>,
) => {
export const useSwapTx = (options?: UseMutationOptions<YoroiUnsignedTx, Error, {entry: YoroiEntry; datum: Datum}>) => {
const {createOrder} = useSwap()
const metadata = [
{
label: 'Yoroi-Swap',
data: {msg: ['Yoroi: Swap B for A Order Request']},
label: '674',
data: {msg: [`${createOrder.selectedPool?.provider}: Swap B for A Order Request`]},
},
]
const wallet = useSelectedWallet()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {Datum} from '@emurgo/yoroi-lib'
import React from 'react'

import {YoroiWallet} from '../../../../yoroi-wallets/cardano/types'
import {YoroiUnsignedTx} from '../../../../yoroi-wallets/types'
import {ConfirmTxWithHW} from './ConfirmTxWithHW'
import {ConfirmTxWithPassword} from './ConfirmTxWithPassword'

type Props = {
wallet: YoroiWallet
unsignedTx: YoroiUnsignedTx
onCancel: () => void
onSuccess: () => void
datum: Datum
}

export const ConfirmTx = ({wallet, onSuccess, onCancel, unsignedTx, datum}: Props) => {
return wallet.isHW ? (
<ConfirmTxWithHW //
wallet={wallet}
unsignedTx={unsignedTx}
onSuccess={onSuccess}
onCancel={onCancel}
/>
) : (
<ConfirmTxWithPassword //
wallet={wallet}
unsignedTx={unsignedTx}
datum={datum}
onSuccess={onSuccess}
onCancel={onCancel}
/>
)
}
Loading

0 comments on commit 8cd4494

Please sign in to comment.