|
1 | 1 | import { eq, gt, sub } from 'biggystring'
|
2 | 2 | import { EdgeCurrencyWallet, EdgeTransaction } from 'edge-core-js'
|
3 | 3 |
|
| 4 | +import { lstrings } from '../../../../locales/strings' |
| 5 | +import { HumanFriendlyError } from '../../../../types/HumanFriendlyError' |
4 | 6 | import { infoServerData } from '../../../../util/network'
|
5 | 7 | import { AssetId, ChangeQuote, PositionAllocation, QuoteAllocation, StakePosition } from '../../types'
|
6 | 8 | import { asInfoServerResponse } from '../../util/internalTypes'
|
7 | 9 | import { StakePolicyConfig } from '../types'
|
8 |
| -import { makeKilnApi } from '../util/kilnUtils' |
| 10 | +import { KilnError, makeKilnApi } from '../util/kilnUtils' |
9 | 11 | import { StakePolicyAdapter } from './types'
|
10 | 12 |
|
11 | 13 | export interface CardanoPooledKilnAdapterConfig {
|
@@ -71,7 +73,21 @@ export const makeCardanoKilnAdapter = (policyConfig: StakePolicyConfig<CardanoPo
|
71 | 73 | throw new Error('Insufficient funds')
|
72 | 74 | }
|
73 | 75 |
|
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 |
75 | 91 | const edgeTx: EdgeTransaction = await wallet.otherMethods.decodeStakingTx(stakeTransaction.unsigned_tx_serialized)
|
76 | 92 |
|
77 | 93 | const allocations: QuoteAllocation[] = [
|
|
0 commit comments