Skip to content

Commit 20e7718

Browse files
committed
Add error_amount_too_low_to_stake_s error to Cardano stake requests
1 parent 2e5e508 commit 20e7718

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

src/components/scenes/Staking/StakeModifyScene.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
StakePosition
1818
} from '../../../plugins/stake-plugins/types'
1919
import { getExchangeDenomByCurrencyCode } from '../../../selectors/DenominationSelectors'
20+
import { HumanFriendlyError } from '../../../types/HumanFriendlyError'
2021
import { useSelector } from '../../../types/reactRedux'
2122
import { EdgeSceneProps } from '../../../types/routerTypes'
2223
import { getCurrencyIconUris } from '../../../util/CdnUris'
@@ -169,6 +170,8 @@ const StakeModifySceneComponent = (props: Props) => {
169170
setErrorMessage(errMessage)
170171
} else if (err instanceof InsufficientFundsError) {
171172
setErrorMessage(lstrings.exchange_insufficient_funds_title)
173+
} else if (err instanceof HumanFriendlyError) {
174+
setErrorMessage(err.message)
172175
} else {
173176
showError(err)
174177
setErrorMessage(lstrings.unknown_error_occurred_fragment)

src/locales/en_US.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ const strings = {
100100
error_paymentprotocol_no_payment_option: 'No currencies available for this Payment Protocol invoice. Accepted currencies: %s',
101101
error_paymentprotocol_tx_verification_failed: 'Payment Protocol transaction verification mismatch',
102102
error_spend_amount_less_then_min_s: 'Spend amount is less than minimum of %s',
103+
error_amount_too_low_to_stake_s: 'The amount %s is too low to stake successfully',
103104

104105
// Warning messages:
105106
warning_low_fee_selected: 'Low Fee Selected',

src/locales/strings/enUS.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"error_paymentprotocol_no_payment_option": "No currencies available for this Payment Protocol invoice. Accepted currencies: %s",
6464
"error_paymentprotocol_tx_verification_failed": "Payment Protocol transaction verification mismatch",
6565
"error_spend_amount_less_then_min_s": "Spend amount is less than minimum of %s",
66-
"error_stake_amount_less_then_min_s": "Amount to be staked is less than minimum of %s",
66+
"error_amount_too_low_to_stake_s": "The amount %s is too low to stake successfully",
6767
"warning_low_fee_selected": "Low Fee Selected",
6868
"warning_custom_fee_selected": "Custom Fee Selected",
6969
"warning_low_or_custom_fee": "Using a low fee may increase the amount of time it takes for your transaction to confirm. In rare instances your transaction can fail.",

src/plugins/stake-plugins/generic/policyAdapters/CardanoKilnAdaptor.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { eq, gt, sub } from 'biggystring'
22
import { EdgeCurrencyWallet, EdgeTransaction } from 'edge-core-js'
33

4+
import { lstrings } from '../../../../locales/strings'
5+
import { HumanFriendlyError } from '../../../../types/HumanFriendlyError'
46
import { infoServerData } from '../../../../util/network'
57
import { AssetId, ChangeQuote, PositionAllocation, QuoteAllocation, StakePosition } from '../../types'
68
import { asInfoServerResponse } from '../../util/internalTypes'
79
import { StakePolicyConfig } from '../types'
8-
import { makeKilnApi } from '../util/kilnUtils'
10+
import { KilnError, makeKilnApi } from '../util/kilnUtils'
911
import { StakePolicyAdapter } from './types'
1012

1113
export interface CardanoPooledKilnAdapterConfig {
@@ -71,7 +73,21 @@ export const makeCardanoKilnAdapter = (policyConfig: StakePolicyConfig<CardanoPo
7173
throw new Error('Insufficient funds')
7274
}
7375

74-
const stakeTransaction = await kiln.adaStakeTransaction(walletAddress, adapterConfig.poolId, accountId)
76+
const result = await kiln.adaStakeTransaction(walletAddress, adapterConfig.poolId, accountId).catch(error => {
77+
if (error instanceof Error) return error
78+
throw error
79+
})
80+
if (result instanceof KilnError) {
81+
if (/Value \d+ less than the minimum UTXO value \d+/.test(result.error)) {
82+
const displayBalance = await wallet.nativeToDenomination(walletBalance, wallet.currencyInfo.currencyCode)
83+
throw new HumanFriendlyError(lstrings.error_amount_too_low_to_stake_s, `${displayBalance} ${wallet.currencyInfo.currencyCode}`)
84+
}
85+
}
86+
if (result instanceof Error) {
87+
throw result
88+
}
89+
90+
const stakeTransaction = result
7591
const edgeTx: EdgeTransaction = await wallet.otherMethods.decodeStakingTx(stakeTransaction.unsigned_tx_serialized)
7692

7793
const allocations: QuoteAllocation[] = [

0 commit comments

Comments
 (0)