Skip to content

Commit

Permalink
Merge branch 'develop' into YV-47-alt
Browse files Browse the repository at this point in the history
  • Loading branch information
jorbuedo committed Nov 20, 2024
2 parents 79bc03c + 27f6446 commit 2ede460
Show file tree
Hide file tree
Showing 15 changed files with 630 additions and 327 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:

jobs:
build:
if: github.event.pull_request.draft == false

runs-on: macos-13
steps:
- uses: maxim-lobanov/setup-xcode@v1
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/wallet-mobile-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ defaults:

jobs:
check:
if: github.event.pull_request.draft == false

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {useMutation} from 'react-query'
import {logger} from '../../kernel/logger/logger'
import {useWalletNavigation} from '../../kernel/navigation'
import {cip30LedgerExtensionMaker} from '../../yoroi-wallets/cardano/cip30/cip30-ledger'
import {useReviewTx} from '../ReviewTx/common/ReviewTxProvider'
import {CreatedByInfoItem} from '../ReviewTx/useCases/ReviewTxScreen/ReviewTx/Overview/OverviewTab'
import {useSelectedWallet} from '../WalletManager/common/hooks/useSelectedWallet'
import {useBrowser} from './common/BrowserProvider'
Expand All @@ -27,7 +26,6 @@ export const useDappConnectorManager = () => {
const navigateTo = useNavigateTo()
const {wallet, meta} = useSelectedWallet()
const {navigateToTxReview} = useWalletNavigation()
const {cborChanged} = useReviewTx()
const {tabs, tabActiveIndex} = useBrowser()
const activeTab = tabs[tabActiveIndex]
const activeTabUrl = activeTab?.url
Expand All @@ -45,11 +43,11 @@ export const useDappConnectorManager = () => {
({cbor, manager}: {cbor: string; manager: DappConnector}) => {
return new Promise<string>((resolve, reject) => {
let shouldResolve = true
cborChanged(cbor)
return manager.getDAppList().then(({dapps}) => {
const matchingDapp =
activeTabOrigin != null ? dapps.find((dapp) => dapp.origins.includes(activeTabOrigin)) : null
navigateToTxReview({
cbor,
createdBy: matchingDapp != null && <CreatedByInfoItem logo={matchingDapp.logo} url={matchingDapp.uri} />,
onConfirm: async () => {
if (!shouldResolve) return
Expand All @@ -67,18 +65,18 @@ export const useDappConnectorManager = () => {
})
})
},
[activeTabOrigin, cborChanged, navigateToTxReview, promptRootKey, navigateTo],
[activeTabOrigin, navigateToTxReview, promptRootKey, navigateTo],
)

const handleSignTxWithHW = React.useCallback(
({cbor, partial, manager}: {cbor: string; partial?: boolean; manager: DappConnector}) => {
return new Promise<Transaction>((resolve, reject) => {
let shouldResolve = true
cborChanged(cbor)
return manager.getDAppList().then(({dapps}) => {
const matchingDapp =
activeTabOrigin != null ? dapps.find((dapp) => dapp.origins.includes(activeTabOrigin)) : null
navigateToTxReview({
cbor,
createdBy: matchingDapp != null && <CreatedByInfoItem logo={matchingDapp.logo} url={matchingDapp.uri} />,
onConfirm: () => {
if (!shouldResolve) return
Expand All @@ -104,7 +102,7 @@ export const useDappConnectorManager = () => {
})
})
},
[activeTabOrigin, cborChanged, navigateToTxReview, navigateTo, signTxWithHW],
[activeTabOrigin, navigateToTxReview, navigateTo, signTxWithHW],
)

return React.useMemo(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/**
* DEPRECATED: This provider needs to be maintained because unsignedTx
* can change during the CATALYST registration funnel (CIP36)
*
* will be eliminated in the very near future
*
* TODO: eliminate the use of unsigned tx entirely
*/

import {castDraft, produce} from 'immer'
import _ from 'lodash'
import React from 'react'
Expand All @@ -21,8 +30,6 @@ export const ReviewTxProvider = ({
const actions = React.useRef<ReviewTxActions>({
unsignedTxChanged: (unsignedTx: ReviewTxState['unsignedTx']) =>
dispatch({type: ReviewTxActionType.UnsignedTxChanged, unsignedTx}),
cborChanged: (cbor: ReviewTxState['cbor']) => dispatch({type: ReviewTxActionType.CborChanged, cbor}),
reset: () => dispatch({type: ReviewTxActionType.Reset}),
}).current

const context = React.useMemo(
Expand All @@ -43,48 +50,27 @@ const reviewTxReducer = (state: ReviewTxState, action: ReviewTxAction) => {
draft.unsignedTx = castDraft(action.unsignedTx)
break

case ReviewTxActionType.CborChanged:
draft.cbor = action.cbor
break

case ReviewTxActionType.Reset:
draft.unsignedTx = castDraft(defaultState.unsignedTx)
draft.cbor = defaultState.cbor
break

default:
throw new Error('[ReviewTxContext] invalid action')
}
})
}

type ReviewTxAction =
| {
type: ReviewTxActionType.UnsignedTxChanged
unsignedTx: ReviewTxState['unsignedTx']
}
| {
type: ReviewTxActionType.CborChanged
cbor: ReviewTxState['cbor']
}
| {
type: ReviewTxActionType.Reset
}
type ReviewTxAction = {
type: ReviewTxActionType.UnsignedTxChanged
unsignedTx: ReviewTxState['unsignedTx']
}

export type ReviewTxState = {
unsignedTx: YoroiUnsignedTx | null
cbor: string | null
}

type ReviewTxActions = {
unsignedTxChanged: (unsignedTx: ReviewTxState['unsignedTx']) => void
cborChanged: (cbor: ReviewTxState['cbor']) => void
reset: () => void
}

const defaultState: ReviewTxState = Object.freeze({
unsignedTx: null,
cbor: null,
})

function missingInit() {
Expand All @@ -94,14 +80,10 @@ function missingInit() {
const initialReviewTxContext: ReviewTxContext = {
...defaultState,
unsignedTxChanged: missingInit,
cborChanged: missingInit,
reset: missingInit,
}

enum ReviewTxActionType {
UnsignedTxChanged = 'unsignedTxChanged',
CborChanged = 'cborChanged',
Reset = 'reset',
}

type ReviewTxContext = ReviewTxState & ReviewTxActions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ export const useStrings = () => {
walletBalanceNFTsTitle: intl.formatMessage(messages.walletBalanceNFTsTitle),
poolDetailsTitle: intl.formatMessage(messages.poolDetailsTitle),
registerStakingKey: intl.formatMessage(messages.registerStakingKey),
poolRegistration: intl.formatMessage(messages.poolRegistration),
poolRetirement: intl.formatMessage(messages.poolRetirement),
moveInstantaneousRewards: intl.formatMessage(messages.moveInstantaneousRewards),
committeeHotAuthorization: intl.formatMessage(messages.committeeHotAuthorization),
committeeColdResign: intl.formatMessage(messages.committeeColdResign),
drepUpdate: intl.formatMessage(messages.drepUpdate),
drepRegistration: intl.formatMessage(messages.drepRegistration),
drepDeregistration: intl.formatMessage(messages.drepDeregistration),
selectAbstain: intl.formatMessage(messages.selectAbstain),
selectNoConfidence: intl.formatMessage(messages.selectNoConfidence),
delegateVotingToDRep: intl.formatMessage(messages.delegateVotingToDRep),
Expand Down Expand Up @@ -253,10 +261,42 @@ const messages = defineMessages({
id: 'txReview.operations.registerStakingKey',
defaultMessage: '!!!Register staking key deposit',
},
drepRegistration: {
id: 'txReview.operations.drepRegistration',
defaultMessage: '!!!Register as a DRep deposit',
},
poolRegistration: {
id: 'txReview.operations.poolRegistration',
defaultMessage: '!!!Pool registration deposit',
},
poolRetirement: {
id: 'txReview.operations.poolRetirement',
defaultMessage: '!!!Pool retirement',
},
drepUpdate: {
id: 'txReview.operations.drepUpdate',
defaultMessage: '!!!Drep update',
},
drepDeregistration: {
id: 'txReview.operations.drepDeregistration',
defaultMessage: '!!!Deregister as a DRep',
},
deregisterStakingKey: {
id: 'txReview.operations.deregisterStakingKey',
defaultMessage: '!!!Deregister staking key',
},
moveInstantaneousRewards: {
id: 'txReview.operations.moveInstantaneousRewards',
defaultMessage: '!!!Move instantaneus rewards',
},
committeeHotAuthorization: {
id: 'txReview.operations.committeeHotAuthorization',
defaultMessage: '!!!Committee hot authorization',
},
committeeColdResign: {
id: 'txReview.operations.committeeColdResign',
defaultMessage: '!!!Committee cold resign',
},
rewardsWithdrawalLabel: {
id: 'txReview.operations.rewardsWithdrawal.label',
defaultMessage: '!!!Staking',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export const useTxBody = ({
const query = useQuery(
['useTxBody', cbor, unsignedTx],
async () => {
// ORDER IS IMPORTANT
// cbor comes from navigation params and unsigned tx from provider
// Reason is unsignedTx can change during the CATALYST registration funnel (CIP36)
// TODO: eliminate the use of unsigned tx entirely
if (cbor != undefined) {
return getCborTxBody(cbor)
} else if (unsignedTx != undefined) {
Expand Down
Loading

0 comments on commit 2ede460

Please sign in to comment.