-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(wallet-mobile): new tx review success and error screens (#3712)
- Loading branch information
Showing
75 changed files
with
979 additions
and
2,293 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
apps/wallet-mobile/src/features/ReviewTx/common/hooks/useNavigateTo.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import {NavigationProp, useNavigation} from '@react-navigation/native' | ||
import * as React from 'react' | ||
|
||
import {ReviewTxRoutes} from '../../../../kernel/navigation' | ||
|
||
export const useNavigateTo = () => { | ||
const navigation = useNavigation<NavigationProp<ReviewTxRoutes>>() | ||
|
||
return React.useRef({ | ||
showSubmittedTxScreen: () => navigation.navigate('review-tx-submitted-tx'), | ||
showFailedTxScreen: () => navigation.navigate('review-tx-failed-tx'), | ||
} as const).current | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
apps/wallet-mobile/src/features/ReviewTx/common/hooks/useSignTx.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import {TransactionWitnessSet} from '@emurgo/cross-csl-core' | ||
import {WalletMeta} from '@yoroi/types/lib/typescript/wallet/meta' | ||
import * as React from 'react' | ||
|
||
import {useModal} from '../../../../components/Modal/ModalContext' | ||
import {cip30ExtensionMaker} from '../../../../yoroi-wallets/cardano/cip30/cip30' | ||
import {YoroiWallet} from '../../../../yoroi-wallets/cardano/types' | ||
import {wrappedCsl} from '../../../../yoroi-wallets/cardano/wrappedCsl' | ||
import {useStrings} from '../../../Discover/common/useStrings' | ||
import {ConfirmRawTxWithOs} from '../../../Swap/common/ConfirmRawTx/ConfirmRawTxWithOs' | ||
import {ConfirmRawTxWithPassword} from '../../../Swap/common/ConfirmRawTx/ConfirmRawTxWithPassword' | ||
import {useSelectedWallet} from '../../../WalletManager/common/hooks/useSelectedWallet' | ||
|
||
export const useSignTx = () => { | ||
const {openModal, closeModal} = useModal() | ||
const {meta, wallet} = useSelectedWallet() | ||
const strings = useStrings() | ||
const modalHeight = 350 | ||
|
||
return React.useCallback( | ||
(cbor: string) => { | ||
const handleOnConfirm = async (rootKey: string) => { | ||
console.log('signTx-123') | ||
const witnesses = await signTx(Buffer.from(cbor).toString('hex'), rootKey, wallet, meta) | ||
|
||
if (!witnesses) throw new Error('kdkdkdk') | ||
await submitTx(cbor, witnesses, wallet) | ||
closeModal() | ||
return | ||
} | ||
|
||
if (meta.isHW) { | ||
throw new Error('Not implemented yet') | ||
} | ||
|
||
if (meta.isEasyConfirmationEnabled) { | ||
openModal(strings.confirmTx, <ConfirmRawTxWithOs onConfirm={handleOnConfirm} />, modalHeight) | ||
return | ||
} | ||
|
||
openModal(strings.confirmTx, <ConfirmRawTxWithPassword onConfirm={handleOnConfirm} />, modalHeight) | ||
}, | ||
[meta, openModal, strings.confirmTx, wallet, closeModal], | ||
) | ||
} | ||
|
||
export const signTx = async (cbor: string, rootKey: string, wallet: YoroiWallet, meta: WalletMeta) => { | ||
const cip30 = cip30ExtensionMaker(wallet, meta) | ||
try { | ||
return cip30.signTx(rootKey, cbor, false) | ||
} catch { | ||
console.log('smksksksksk') | ||
} | ||
} | ||
|
||
export const submitTx = async (cbor: string, witnesses: TransactionWitnessSet, wallet: YoroiWallet) => { | ||
const {csl, release} = wrappedCsl() | ||
|
||
try { | ||
const tx = await csl.Transaction.fromHex(cbor) | ||
const txBody = await tx.body() | ||
const signedTx = await csl.Transaction.new(txBody, witnesses, undefined) | ||
const signedTxBytes = await signedTx.toBytes() | ||
|
||
await wallet.submitTransaction(Buffer.from(signedTxBytes).toString('base64')) | ||
} finally { | ||
release() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.