diff --git a/stores/CashuStore.ts b/stores/CashuStore.ts index 507a73a6e..ca2f029ba 100644 --- a/stores/CashuStore.ts +++ b/stores/CashuStore.ts @@ -1508,10 +1508,10 @@ export default class CashuStore { return; } catch (e: any) { - const error = e; + const errorMsg = errorToUserFriendly(e); runInAction(() => { this.payReq = undefined; - this.getPayReqError = errorToUserFriendly(error); + this.getPayReqError = errorMsg; this.loading = false; }); } diff --git a/stores/ChannelsStore.ts b/stores/ChannelsStore.ts index a5678ee71..43753a740 100644 --- a/stores/ChannelsStore.ts +++ b/stores/ChannelsStore.ts @@ -931,10 +931,11 @@ export default class ChannelsStore { }) .then((data: any) => { if (data.publish_error) { + const errorMsg = errorToUserFriendly( + data.publish_error + ); runInAction(() => { - this.errorMsgChannel = errorToUserFriendly( - data.publish_error - ); + this.errorMsgChannel = errorMsg; this.output_index = null; this.funding_txid_str = null; this.errorOpenChannel = true; @@ -993,9 +994,10 @@ export default class ChannelsStore { ); } }) - .catch((error: any) => + .catch((error: any) => { + const errorMsg = errorToUserFriendly(error); runInAction(() => { - this.errorMsgChannel = errorToUserFriendly(error); + this.errorMsgChannel = errorMsg; this.output_index = null; this.funding_txid_str = null; this.errorOpenChannel = true; @@ -1003,12 +1005,13 @@ export default class ChannelsStore { this.channelRequest = null; this.peerSuccess = false; this.channelSuccess = false; - }) - ); + }); + }); }) - .catch((error: any) => + .catch((error: any) => { + const errorMsg = errorToUserFriendly(error); runInAction(() => { - this.errorMsgChannel = errorToUserFriendly(error); + this.errorMsgChannel = errorMsg; this.output_index = null; this.funding_txid_str = null; this.errorOpenChannel = true; @@ -1016,8 +1019,8 @@ export default class ChannelsStore { this.channelRequest = null; this.peerSuccess = false; this.channelSuccess = false; - }) - ); + }); + }); }; @action @@ -1183,9 +1186,10 @@ export default class ChannelsStore { this.connectingToPeer = false; }) ) - .catch((error: Error) => + .catch((error: Error) => { + const errorMsg = errorToUserFriendly(error); runInAction(() => { - this.errorMsgChannel = errorToUserFriendly(error); + this.errorMsgChannel = errorMsg; this.output_index = null; this.funding_txid_str = null; this.errorOpenChannel = true; @@ -1194,8 +1198,8 @@ export default class ChannelsStore { this.channelRequest = null; this.peerSuccess = false; this.channelSuccess = false; - }) - ); + }); + }); } }; diff --git a/stores/FeeStore.ts b/stores/FeeStore.ts index f113d8323..72e26020b 100644 --- a/stores/FeeStore.ts +++ b/stores/FeeStore.ts @@ -189,8 +189,9 @@ export default class FeeStore { }); }) .catch((err: any) => { + const errorMsg = errorToUserFriendly(err); runInAction(() => { - this.setFeesErrorMsg = errorToUserFriendly(err); + this.setFeesErrorMsg = errorMsg; this.loading = false; this.setFeesError = true; }); @@ -369,16 +370,18 @@ export default class FeeStore { }); }) .catch((err: Error) => { + const errorMsg = errorToUserFriendly(err); runInAction(() => { this.bumpFeeError = true; - this.bumpFeeErrorMsg = errorToUserFriendly(err); + this.bumpFeeErrorMsg = errorMsg; this.loading = false; }); }); } else { + const errorMsg = errorToUserFriendly(err); runInAction(() => { this.bumpFeeError = true; - this.bumpFeeErrorMsg = errorToUserFriendly(err); + this.bumpFeeErrorMsg = errorMsg; this.loading = false; }); } diff --git a/stores/LSPStore.ts b/stores/LSPStore.ts index c1293ce91..5aeb90421 100644 --- a/stores/LSPStore.ts +++ b/stores/LSPStore.ts @@ -200,11 +200,10 @@ export default class LSPStore { ); } catch (e) {} } else { + const errorMsg = errorToUserFriendly(data.message); runInAction(() => { this.flow_error = true; - this.flow_error_msg = errorToUserFriendly( - data.message - ); + this.flow_error_msg = errorMsg; // handle LSP geoblocking :( if ( this.error_msg.includes( @@ -410,9 +409,10 @@ export default class LSPStore { resolve(response); }) .catch((error: any) => { + const errorMsg = errorToUserFriendly(error); runInAction(() => { this.error = true; - this.error_msg = errorToUserFriendly(error); + this.error_msg = errorMsg; }); reject(error); }); @@ -638,28 +638,30 @@ export default class LSPStore { ) .then((response) => { const responseData = JSON.parse(response.data); - runInAction(() => { - if (responseData.error) { + if (responseData.error) { + const errorMsg = errorToUserFriendly(responseData.message); + runInAction(() => { this.error = true; - this.error_msg = errorToUserFriendly( - responseData.message - ); + this.error_msg = errorMsg; this.loadingLSPS1 = false; - } else { + }); + } else { + runInAction(() => { this.createOrderResponse = responseData; this.loadingLSPS1 = false; console.log('Response received:', responseData); - } - }); + }); + } }) .catch((error) => { console.error( 'Error sending (create_order) custom message:', error ); + const errorMsg = errorToUserFriendly(error); runInAction(() => { this.error = true; - this.error_msg = errorToUserFriendly(error); + this.error_msg = errorMsg; this.loadingLSPS1 = false; }); }); @@ -735,9 +737,10 @@ export default class LSPStore { }) .catch((error) => { console.error('Error sending custom message:', error); + const errorMsg = errorToUserFriendly(error); runInAction(() => { this.error = true; - this.error_msg = errorToUserFriendly(error); + this.error_msg = errorMsg; this.loadingLSPS1 = false; }); }); diff --git a/stores/NodeInfoStore.ts b/stores/NodeInfoStore.ts index 0a2e1c95a..4babb0f69 100644 --- a/stores/NodeInfoStore.ts +++ b/stores/NodeInfoStore.ts @@ -88,8 +88,9 @@ export default class NodeInfoStore { resolve('Old getNodeInfo call'); return; } + const errorMsg = errorToUserFriendly(error.toString()); runInAction(() => { - this.errorMsg = errorToUserFriendly(error.toString()); + this.errorMsg = errorMsg; this.handleGetNodeInfoError(); }); reject(error); @@ -111,8 +112,9 @@ export default class NodeInfoStore { return this.networkInfo; }) .catch((error: any) => { + const errorMsg = errorToUserFriendly(error.toString()); runInAction(() => { - this.errorMsg = errorToUserFriendly(error.toString()); + this.errorMsg = errorMsg; this.handleGetNetworkInfoError(); }); }); diff --git a/stores/OffersStore.ts b/stores/OffersStore.ts index e099b5de9..f69e6074e 100644 --- a/stores/OffersStore.ts +++ b/stores/OffersStore.ts @@ -42,9 +42,10 @@ export default class OffersStore { return data; }) .catch((e: any) => { + const errorMsg = errorToUserFriendly(e); runInAction(() => { this.error = true; - this.error_msg = errorToUserFriendly(e); + this.error_msg = errorMsg; this.loading = false; }); }); @@ -62,9 +63,10 @@ export default class OffersStore { return data; }) .catch((e: any) => { + const errorMsg = errorToUserFriendly(e); runInAction(() => { this.error = true; - this.error_msg = errorToUserFriendly(e); + this.error_msg = errorMsg; this.loading = false; }); }); diff --git a/stores/TransactionsStore.ts b/stores/TransactionsStore.ts index 6055d327a..c4995e6c2 100644 --- a/stores/TransactionsStore.ts +++ b/stores/TransactionsStore.ts @@ -172,18 +172,20 @@ export default class TransactionsStore { }); return data; } else { + const errorMsg = errorToUserFriendly(data); runInAction(() => { - this.error_msg = errorToUserFriendly(data); + this.error_msg = errorMsg; this.error = true; this.loading = false; }); } }) .catch((err: any) => { + const errorMsg = errorToUserFriendly( + err?.error || err?.message || err?.toString() + ); runInAction(() => { - this.error_msg = errorToUserFriendly( - err?.error || err?.message || err?.toString() - ); + this.error_msg = errorMsg; this.error = true; this.loading = false; }); @@ -194,26 +196,28 @@ export default class TransactionsStore { tx_hex }) .then((data: any) => { - runInAction(() => { - if (data.publish_error) { - this.error_msg = errorToUserFriendly( - data.publish_error - ); + if (data.publish_error) { + const errorMsg = errorToUserFriendly(data.publish_error); + runInAction(() => { + this.error_msg = errorMsg; this.error = true; this.loading = false; - } else { + }); + } else { + runInAction(() => { this.txid = txid; this.publishSuccess = true; this.loading = false; this.channelsStore.resetOpenChannel(); - } - }); + }); + } }) .catch((error: any) => { + const errorMsg = errorToUserFriendly( + error.publish_error || error.message + ); runInAction(() => { - this.error_msg = errorToUserFriendly( - error.publish_error || error.message - ); + this.error_msg = errorMsg; this.error = true; this.loading = false; }); @@ -232,8 +236,9 @@ export default class TransactionsStore { return BackendUtils.finalizePsbt({ funded_psbt }) .then((data: any) => this.broadcast(data.raw_final_tx)) .catch((error: any) => { + const errorMsg = errorToUserFriendly(error.message); runInAction(() => { - this.error_msg = errorToUserFriendly(error.message); + this.error_msg = errorMsg; this.error = true; this.loading = false; }); @@ -260,10 +265,11 @@ export default class TransactionsStore { resolve(true); } catch (error: any) { + const errorMsg = errorToUserFriendly( + error?.message || error + ); runInAction(() => { - this.error_msg = errorToUserFriendly( - error?.message || error - ); + this.error_msg = errorMsg; this.error = true; this.loading = false; }); @@ -287,14 +293,15 @@ export default class TransactionsStore { } }) .then((data: any) => { - runInAction(() => { - if (data.publish_error) { - this.error_msg = errorToUserFriendly( - data.publish_error - ); + if (data.publish_error) { + const errorMsg = errorToUserFriendly(data.publish_error); + runInAction(() => { + this.error_msg = errorMsg; this.error = true; this.loading = false; - } else { + }); + } else { + runInAction(() => { try { // Parse the PSBT const psbt = bitcoin.Psbt.fromBase64(signed_psbt); @@ -309,12 +316,13 @@ export default class TransactionsStore { this.publishSuccess = true; this.loading = false; this.channelsStore.resetOpenChannel(); - } - }); + }); + } }) .catch((error: any) => { + const errorMsg = errorToUserFriendly(error.message); runInAction(() => { - this.error_msg = errorToUserFriendly(error.message); + this.error_msg = errorMsg; this.error = true; this.loading = false; }); @@ -334,14 +342,15 @@ export default class TransactionsStore { } }) .then((data: any) => { - runInAction(() => { - if (data.publish_error) { - this.error_msg = errorToUserFriendly( - data.publish_error - ); + if (data.publish_error) { + const errorMsg = errorToUserFriendly(data.publish_error); + runInAction(() => { + this.error_msg = errorMsg; this.error = true; this.loading = false; - } else { + }); + } else { + runInAction(() => { try { // Parse the tx const tx = bitcoin.Transaction.fromHex(tx_hex); @@ -353,12 +362,13 @@ export default class TransactionsStore { this.publishSuccess = true; this.loading = false; this.channelsStore.resetOpenChannel(); - } - }); + }); + } }) .catch((error: any) => { + const errorMsg = errorToUserFriendly(error.message); runInAction(() => { - this.error_msg = errorToUserFriendly(error.message); + this.error_msg = errorMsg; this.error = true; this.loading = false; }); @@ -427,8 +437,9 @@ export default class TransactionsStore { }); }) .catch((error: any) => { + const errorMsg = errorToUserFriendly(error.message); runInAction(() => { - this.error_msg = errorToUserFriendly(error.message); + this.error_msg = errorMsg; this.error = true; this.crafting = false; this.loading = false; @@ -491,8 +502,9 @@ export default class TransactionsStore { }); }) .catch((error: Error) => { + const errorMsg = errorToUserFriendly(error); runInAction(() => { - this.error_msg = errorToUserFriendly(error); + this.error_msg = errorMsg; this.error = true; this.loading = false; });