diff --git a/app/frontend/actions.ts b/app/frontend/actions.ts index aac11a21b8..0111dd01e3 100644 --- a/app/frontend/actions.ts +++ b/app/frontend/actions.ts @@ -810,6 +810,37 @@ export default ({setState, getState}: {setState: SetStateFn; getState: GetStateF stopLoadingAction(state, {}) } + const redeemRewards = async (state) => { + loadingAction(state, 'Preparing transaction...') + const address = await wallet.getChangeAddress() + const coins = state.shelleyBalances.rewardsAccountBalance + const balance = state.balance + let plan + try { + plan = await prepareTxPlan({ + address, + coins, + txType: 'redeem', + }) + } catch (e) { + setErrorState('transactionSubmissionError', e, { + shouldShowTransactionErrorModal: true, + }) + return + } + if (balance < (plan.fee || plan.estimatedFee)) { + setErrorState('transactionSubmissionError', NamedError('NonStakingConversionError')) + setState({ + shouldShowTransactionErrorModal: true, + }) + stopLoadingAction(state, {}) + return + } + setTransactionSummary('stake', plan, coins) + confirmTransaction(getState(), 'convert') + stopLoadingAction(state, {}) + } + const updateDonation = (state, e) => { if (state.checkedDonationType === e.target.id && e.target.id !== 'custom') { // when clicking already selected button @@ -1215,5 +1246,6 @@ export default ({setState, getState}: {setState: SetStateFn; getState: GetStateF selectAdaliteStakepool, convertNonStakingUtxos, loadErrorBannerContent, + redeemRewards, } } diff --git a/app/frontend/components/pages/delegations/shelleyBalances.tsx b/app/frontend/components/pages/delegations/shelleyBalances.tsx index 827ade2fb1..0f7e069c9a 100644 --- a/app/frontend/components/pages/delegations/shelleyBalances.tsx +++ b/app/frontend/components/pages/delegations/shelleyBalances.tsx @@ -12,6 +12,7 @@ const shelleyBalances = ({ balance, reloadWalletInfo, convertNonStakingUtxos, + redeemRewards, }) => (

@@ -71,7 +72,7 @@ const shelleyBalances = ({ : `${printAda(rewardsAccountBalance)}`}

- diff --git a/app/frontend/wallet/shelley-wallet.ts b/app/frontend/wallet/shelley-wallet.ts index 0765f9fdfc..c13722941e 100644 --- a/app/frontend/wallet/shelley-wallet.ts +++ b/app/frontend/wallet/shelley-wallet.ts @@ -333,7 +333,8 @@ const ShelleyWallet = ({config, randomInputSeed, randomChangeSeed, cryptoProvide changeAddress, accountAddress, poolHash, - !stakingKeyRegistered + !stakingKeyRegistered, + txType === 'redeem' ) return plan } @@ -365,7 +366,7 @@ const ShelleyWallet = ({config, randomInputSeed, randomChangeSeed, cryptoProvide sendAda: utxoTxPlanner, convert: utxoTxPlanner, delegate: utxoTxPlanner, - // redeem: accountTxPlanner, + redeem: utxoTxPlanner, } return await txPlanners[args.txType](args, accountAddress) } diff --git a/app/frontend/wallet/shelley/shelley-transaction-planner.ts b/app/frontend/wallet/shelley/shelley-transaction-planner.ts index b80a689fb4..a595034f46 100644 --- a/app/frontend/wallet/shelley/shelley-transaction-planner.ts +++ b/app/frontend/wallet/shelley/shelley-transaction-planner.ts @@ -216,7 +216,8 @@ export function selectMinimalTxPlan( changeAddress, accountAddress, poolHash = null, - registerStakingKey = false + registerStakingKey = false, + isRedeem = false ): TxPlan | NoTxPlan { const certs = [] if (poolHash && registerStakingKey) {