Skip to content

Commit b913ca3

Browse files
authored
Merge branch 'develop' into chore/cardano-node-1.35.2
2 parents aee8a3b + af8e56a commit b913ca3

File tree

4 files changed

+91
-90
lines changed

4 files changed

+91
-90
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
### Chores
1111

1212
- Updated cardano-node to 1.35.2 ([PR 3021](https://github.com/input-output-hk/daedalus/pull/3021))
13+
- Fix `darwin-launcher.go` to replace its process image with `cardano-launcher` (binary), and not swallow `stdout` ([PR 3023](https://github.com/input-output-hk/daedalus/pull/3023))
1314
- Updated cardano-node to 1.35.1 ([PR 3012](https://github.com/input-output-hk/daedalus/pull/3012))
1415

1516
### Features

nix/darwin-launcher.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ import (
55
"os"
66
"os/exec"
77
"path/filepath"
8+
"syscall"
89
)
910

1011
func main() {
12+
fmt.Fprintf(os.Stderr, "darwin-launcher: PID = %d\n", os.Getpid())
13+
1114
ex, err := os.Executable()
1215
if err != nil {
1316
panic(err)
@@ -17,14 +20,23 @@ func main() {
1720

1821
os.Setenv("PATH", fmt.Sprintf("%s:%s", installDir, os.Getenv("PATH")))
1922

20-
launcherConfig := filepath.Join(installDir, "../Resources/launcher-config.yaml")
21-
helper := filepath.Join(installDir, "../Resources/helper")
22-
23+
launcherConfigPath := filepath.Join(installDir, "../Resources/launcher-config.yaml")
24+
helperPath := filepath.Join(installDir, "../Resources/helper")
2325

24-
if err = exec.Command(helper).Run(); err != nil {
26+
helperCmd := exec.Command(helperPath)
27+
helperCmd.Stdout = os.Stdout
28+
helperCmd.Stderr = os.Stderr
29+
if err := helperCmd.Run(); err != nil {
2530
panic(err)
2631
}
27-
if err = exec.Command("cardano-launcher", "--config", launcherConfig).Run(); err != nil {
28-
panic(err)
32+
33+
// Replace the current process (otherwise WDIO complains in end-to-end tests):
34+
img := filepath.Join(installDir, "cardano-launcher")
35+
argv := []string{"cardano-launcher", "--config", launcherConfigPath}
36+
env := os.Environ()
37+
if err := syscall.Exec(img, argv, env); err != nil {
38+
fmt.Println(err)
2939
}
40+
41+
fmt.Fprintf(os.Stderr, "this won’t happen\n")
3042
}

source/renderer/app/api/api.ts

Lines changed: 12 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ import { getAssets } from './assets/requests/getAssets';
228228
import { getAccountPublicKey } from './wallets/requests/getAccountPublicKey';
229229
import { doesWalletRequireAdaToRemainToSupportTokens } from './utils/apiHelpers';
230230
import { AssetLocalData } from '../types/localDataTypes';
231+
import { handleNotEnoughMoneyError } from './errors';
231232

232233
export 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-
/(Expected min coin value: +)([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-
/(Expected min coin value: +)([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 (

source/renderer/app/api/errors.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
import BigNumber from 'bignumber.js';
2+
import get from 'lodash/get';
13
import { defineMessages } from 'react-intl';
4+
import ApiError, { ErrorType } from '../domains/ApiError';
25

36
export const messages = defineMessages({
47
// common
@@ -119,3 +122,60 @@ export const messages = defineMessages({
119122
'"Balance after transaction would not leave enough ada in the wallet to support tokens remaining in wallet',
120123
},
121124
});
125+
126+
type Balances = {
127+
walletBalance: BigNumber;
128+
availableBalance: BigNumber;
129+
rewardsBalance: BigNumber;
130+
};
131+
132+
export const handleNotEnoughMoneyError = (
133+
error: ErrorType,
134+
balance: Balances
135+
) => {
136+
let notEnoughMoneyError;
137+
138+
const { walletBalance, availableBalance, rewardsBalance } = balance;
139+
140+
if (walletBalance.gt(availableBalance)) {
141+
// 1. Amount exceeds availableBalance due to pending transactions:
142+
// - walletBalance > availableBalance
143+
// = show "Cannot calculate fees while there are pending transactions."
144+
notEnoughMoneyError = 'canNotCalculateTransactionFees';
145+
} else if (
146+
!walletBalance.isZero() &&
147+
walletBalance.isEqualTo(rewardsBalance)
148+
) {
149+
// 2. Wallet contains only rewards:
150+
// - walletBalance === rewardsBalance
151+
// = show "Cannot send from a wallet that contains only rewards balances."
152+
notEnoughMoneyError = 'inputsDepleted';
153+
} else {
154+
// 3. Amount exceeds walletBalance:
155+
// - walletBalance === availableBalance
156+
// = show "Not enough Ada. Try sending a smaller amount."
157+
notEnoughMoneyError = 'notEnoughFundsForTransaction';
158+
}
159+
160+
// ApiError with logging showcase
161+
throw new ApiError(error, {
162+
// @ts-ignore ts-migrate(2322) FIXME: Type 'boolean' is not assignable to type 'Record<s... Remove this comment to see the full error message
163+
logError: true,
164+
msg: 'AdaApi::calculateTransactionFee error',
165+
})
166+
.set(notEnoughMoneyError, true)
167+
.where('code', 'not_enough_money')
168+
.set('utxoTooSmall', true, {
169+
// @ts-ignore ts-migrate(2339) FIXME: Property 'exec' does not exist on type '{}'.
170+
minimumAda: get(
171+
/(Expected min coin value: +)([0-9]+.[0-9]+)/.exec(error.message),
172+
2,
173+
0
174+
),
175+
})
176+
.where('code', 'utxo_too_small')
177+
.set('invalidAddress')
178+
.where('code', 'bad_request')
179+
.inc('message', 'Unable to decode Address')
180+
.result();
181+
};

0 commit comments

Comments
 (0)