Skip to content

Commit

Permalink
remove obsolete parameter localize
Browse files Browse the repository at this point in the history
  • Loading branch information
myxmaster committed Dec 23, 2024
1 parent f5f2b6e commit baf2718
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 50 deletions.
1 change: 0 additions & 1 deletion stores/TransactionsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,6 @@ export default class TransactionsStore {
)
: errorToUserFriendly(
result.failure_reason,
true,
isKeysend ? ['Keysend'] : undefined
)) || errorToUserFriendly(result.payment_error);
}
Expand Down
39 changes: 14 additions & 25 deletions utils/ErrorUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ describe('ErrorUtils', () => {
"details": []
}`,
name: 'test'
}),
false
})
)
).toEqual('transaction output is dust');
expect(
Expand All @@ -29,8 +28,7 @@ describe('ErrorUtils', () => {
"details": []
}`,
name: 'test'
}),
false
})
)
).toEqual(
'proto: (line 1:126): invalid value for uint64 type: 0.1'
Expand All @@ -47,8 +45,7 @@ describe('ErrorUtils', () => {
}
`,
name: 'test'
}),
false
})
)
).toEqual('invoice is already paid');
expect(
Expand All @@ -63,8 +60,7 @@ describe('ErrorUtils', () => {
}
`,
name: 'test'
}),
false
})
)
).toEqual(
'Host unreachable. Try restarting your node or its Tor process.'
Expand All @@ -75,23 +71,21 @@ describe('ErrorUtils', () => {
message:
'Error: called `Result::unwrap()` on an `Err` value: BootStrapError("Timeout waiting for bootstrap")',
name: 'test'
}),
false
})
)
).toEqual(
'Error starting up Tor on your phone. Try restarting Zeus. If the problem persists consider using the Orbot app to connect to Tor, or using an alternative connection method like Lightning Node Connect or Tailscale.'
'Error starting up Tor on your phone. Try restarting ZEUS. If the problem persists consider using the Orbot app to connect to Tor, or using an alternative connection method like Lightning Node Connect or Tailscale.'
);
expect(
errorToUserFriendly(
Object.assign(new Error(), {
message:
'Error: called `Result::unwrap()` on an `Err` value: BootStrapError("Timeout waiting for boostrap")',
name: 'test'
}),
false
})
)
).toEqual(
'Error starting up Tor on your phone. Try restarting Zeus. If the problem persists consider using the Orbot app to connect to Tor, or using an alternative connection method like Lightning Node Connect or Tailscale.'
'Error starting up Tor on your phone. Try restarting ZEUS. If the problem persists consider using the Orbot app to connect to Tor, or using an alternative connection method like Lightning Node Connect or Tailscale.'
);
});

Expand All @@ -102,8 +96,7 @@ describe('ErrorUtils', () => {
message:
'Error: Failed to connect to /can-be-any-host:8082',
name: 'test'
}),
false
})
)
).toEqual(
'Unable to connect to node. Please verify the host and port are correct and the service is running.'
Expand All @@ -117,7 +110,6 @@ describe('ErrorUtils', () => {
message: 'FAILURE_REASON_INCORRECT_PAYMENT_DETAILS',
name: 'test'
}),
true,
['UnhandledContext']
)
).toEqual(
Expand All @@ -132,7 +124,6 @@ describe('ErrorUtils', () => {
message: 'FAILURE_REASON_INCORRECT_PAYMENT_DETAILS',
name: 'test'
}),
true,
['Keysend']
)
).toEqual(
Expand All @@ -146,23 +137,21 @@ describe('ErrorUtils', () => {
Object.assign(new Error(), {
message: 'Random message',
name: 'test'
}),
false
})
)
).toEqual('Random message');
});

it('Return string if error is sent as a string', () => {
expect(
errorToUserFriendly(new Error('Payment timed out'), false)
).toEqual('Payment timed out');
expect(errorToUserFriendly(new Error('Payment timed out'))).toEqual(
'Payment timed out'
);
});

it('Handles PascalCased LSP error messages', () => {
expect(
errorToUserFriendly(
new Error('ChannelExpiryBlocksTooHighInCreateOrderRequest'),
false
new Error('ChannelExpiryBlocksTooHighInCreateOrderRequest')
)
).toEqual('Channel expiry blocks too high in create order request');
});
Expand Down
37 changes: 13 additions & 24 deletions utils/ErrorUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ const userFriendlyErrors: any = {

const pascalCase = /^[A-Z](([a-z0-9]+[A-Z]?)*)$/;

const errorToUserFriendly = (
error: Error,
localize = true,
errorContext?: string[]
) => {
const errorToUserFriendly = (error: Error, errorContext?: string[]) => {
let errorMessage: string = error?.message;
let errorObject: any;

Expand Down Expand Up @@ -58,27 +54,20 @@ const errorToUserFriendly = (
? userFriendlyErrors[matchingPattern]
: null;

if (localize) {
const localeString = require('./LocaleUtils').localeString;
let baseError = localeKey
? localeString(localeKey)?.replace('Zeus', 'ZEUS')
: errorMsg;
const localeString = require('./LocaleUtils').localeString;
let baseError = localeKey
? localeString(localeKey)?.replace('Zeus', 'ZEUS')
: errorMsg;

if (
errorContext?.includes('Keysend') &&
errorMsg === 'FAILURE_REASON_INCORRECT_PAYMENT_DETAILS'
) {
baseError +=
' ' +
localeString(
'error.failureReasonIncorrectPaymentDetailsKeysend'
);
}
return baseError;
} else {
const EN = require('../locales/en.json');
return localeKey ? EN[localeKey] : errorMsg;
if (
errorContext?.includes('Keysend') &&
errorMsg === 'FAILURE_REASON_INCORRECT_PAYMENT_DETAILS'
) {
baseError +=
' ' +
localeString('error.failureReasonIncorrectPaymentDetailsKeysend');
}
return baseError;
};

export { errorToUserFriendly };

0 comments on commit baf2718

Please sign in to comment.