@@ -228,6 +228,7 @@ import { getAssets } from './assets/requests/getAssets';
228228import { getAccountPublicKey } from './wallets/requests/getAccountPublicKey' ;
229229import { doesWalletRequireAdaToRemainToSupportTokens } from './utils/apiHelpers' ;
230230import { AssetLocalData } from '../types/localDataTypes' ;
231+ import { handleNotEnoughMoneyError } from './errors' ;
231232
232233export default class AdaApi {
233234 config : RequestConfig ;
@@ -1061,51 +1062,14 @@ export default class AdaApi {
10611062 minimumAda,
10621063 } ;
10631064 } catch ( error ) {
1064- let notEnoughMoneyError ;
1065-
1066- if ( walletBalance . gt ( availableBalance ) ) {
1067- // 1. Amount exceeds availableBalance due to pending transactions:
1068- // - walletBalance > availableBalance
1069- // = show "Cannot calculate fees while there are pending transactions."
1070- notEnoughMoneyError = 'canNotCalculateTransactionFees' ;
1071- } else if (
1072- ! walletBalance . isZero ( ) &&
1073- walletBalance . isEqualTo ( rewardsBalance )
1074- ) {
1075- // 2. Wallet contains only rewards:
1076- // - walletBalance === rewardsBalance
1077- // = show "Cannot send from a wallet that contains only rewards balances."
1078- notEnoughMoneyError = 'inputsDepleted' ;
1079- } else {
1080- // 3. Amount exceeds walletBalance:
1081- // - walletBalance === availableBalance
1082- // = show "Not enough Ada. Try sending a smaller amount."
1083- notEnoughMoneyError = 'notEnoughFundsForTransaction' ;
1084- }
1085-
1086- // ApiError with logging showcase
1087- throw new ApiError ( error , {
1088- // @ts -ignore ts-migrate(2322) FIXME: Type 'boolean' is not assignable to type 'Record<s... Remove this comment to see the full error message
1089- logError : true ,
1090- msg : 'AdaApi::calculateTransactionFee error' ,
1091- } )
1092- . set ( notEnoughMoneyError , true )
1093- . where ( 'code' , 'not_enough_money' )
1094- . set ( 'utxoTooSmall' , true , {
1095- // @ts -ignore ts-migrate(2339) FIXME: Property 'exec' does not exist on type '{}'.
1096- minimumAda : get (
1097- / ( E x p e c t e d m i n c o i n v a l u e : + ) ( [ 0 - 9 ] + .[ 0 - 9 ] + ) / . exec ( error . message ) ,
1098- 2 ,
1099- 0
1100- ) ,
1101- } )
1102- . where ( 'code' , 'utxo_too_small' )
1103- . set ( 'invalidAddress' )
1104- . where ( 'code' , 'bad_request' )
1105- . inc ( 'message' , 'Unable to decode Address' )
1106- . result ( ) ;
1065+ handleNotEnoughMoneyError ( error , {
1066+ walletBalance,
1067+ availableBalance,
1068+ rewardsBalance,
1069+ } ) ;
11071070 }
11081071 } ;
1072+
11091073 selectCoins = async ( request : {
11101074 walletId : string ;
11111075 walletBalance : BigNumber ;
@@ -1270,48 +1234,12 @@ export default class AdaApi {
12701234 logger . error ( 'AdaApi::selectCoins error' , {
12711235 error,
12721236 } ) ;
1273- let notEnoughMoneyError ;
12741237
1275- if ( walletBalance . gt ( availableBalance ) ) {
1276- // 1. Amount exceeds availableBalance due to pending transactions:
1277- // - walletBalance > availableBalance
1278- // = show "Cannot calculate fees while there are pending transactions."
1279- notEnoughMoneyError = 'canNotCalculateTransactionFees' ;
1280- } else if (
1281- ! walletBalance . isZero ( ) &&
1282- walletBalance . isEqualTo ( rewardsBalance )
1283- ) {
1284- // 2. Wallet contains only rewards:
1285- // - walletBalance === rewardsBalance
1286- // = show "Cannot send from a wallet that contains only rewards balances."
1287- notEnoughMoneyError = 'inputsDepleted' ;
1288- } else {
1289- // 3. Amount exceeds walletBalance:
1290- // - walletBalance === availableBalance
1291- // = show "Not enough Ada. Try sending a smaller amount."
1292- notEnoughMoneyError = 'notEnoughFundsForTransaction' ;
1293- }
1294-
1295- // ApiError with logging showcase
1296- throw new ApiError ( error , {
1297- // @ts -ignore ts-migrate(2322) FIXME: Type 'boolean' is not assignable to type 'Record<s... Remove this comment to see the full error message
1298- logError : true ,
1299- msg : 'AdaApi::calculateTransactionFee error' ,
1300- } )
1301- . set ( notEnoughMoneyError , true )
1302- . where ( 'code' , 'not_enough_money' )
1303- . set ( 'utxoTooSmall' , true , {
1304- minimumAda : get (
1305- / ( E x p e c t e d m i n c o i n v a l u e : + ) ( [ 0 - 9 ] + .[ 0 - 9 ] + ) / . exec ( error . message ) ,
1306- 2 ,
1307- 0
1308- ) ,
1309- } )
1310- . where ( 'code' , 'utxo_too_small' )
1311- . set ( 'invalidAddress' )
1312- . where ( 'code' , 'bad_request' )
1313- . inc ( 'message' , 'Unable to decode Address' )
1314- . result ( ) ;
1238+ handleNotEnoughMoneyError ( error , {
1239+ walletBalance,
1240+ availableBalance,
1241+ rewardsBalance,
1242+ } ) ;
13151243 }
13161244 } ;
13171245 createExternalTransaction = async (
0 commit comments