Relay fund-transfer failure reason to user

## Issue
Was just getting a generic "Transaction failed" and had to check devTools to figure out what's wrong.
This commit is contained in:
infinite-persistence 2022-05-05 16:41:47 +08:00
parent f550be4306
commit e3996f458f
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0
3 changed files with 8 additions and 1 deletions

View file

@ -860,6 +860,7 @@
"Successfully abandoned your support.": "Successfully abandoned your support.",
"Transaction failed": "Transaction failed",
"Insufficient credits": "Insufficient credits",
"Insufficient credits to account for transaction fees.": "Insufficient credits to account for transaction fees.",
"Error abandoning your claim/support": "Error abandoning your claim/support",
"Error unlocking your tip": "Error unlocking your tip",
"No stats found": "No stats found",

View file

@ -10,6 +10,7 @@ import {
selectPendingConsolidateTxid,
selectPendingMassClaimTxid,
} from 'redux/selectors/wallet';
import { resolveApiMessage } from 'util/api-message';
import { creditsToString } from 'util/format-credits';
import { selectMyClaimsRaw, selectClaimsById } from 'redux/selectors/claims';
import { doFetchChannelListMine, doFetchClaimListMine, doClaimSearch } from 'redux/actions/claims';
@ -317,6 +318,7 @@ export function doSendDraftTransaction(address, amount) {
dispatch(
doToast({
message: __('Transaction failed'),
subMessage: resolveApiMessage(error?.message),
isError: true,
})
);

View file

@ -43,6 +43,10 @@ const MESSAGE_MAP: Array<ApiMsgConfig> = Object.freeze([
originalMsg: /^You only watched content (.*) days in the last week and it needs to be at least (.*) to get the reward.$/,
replacement: 'You only watched content for %1% days in the last week. It needs to be at least %2% to get the reward.',
},
{
originalMsg: 'Not enough funds to cover this transaction.',
replacement: 'Insufficient credits to account for transaction fees.',
},
// {
// originalMsg: /^Earn a random reward of at least 0.1 LBC for watching cool stuff at least 3 days during the week. You can claim it again in (.*)$/,
// replacement: 'Earn a random reward of at least 0.1 LBC for watching cool stuff at least 3 days during the week. You can claim it again in %1%',
@ -62,7 +66,7 @@ const MESSAGE_MAP: Array<ApiMsgConfig> = Object.freeze([
* @param message
* @returns {string}
*/
export function resolveApiMessage(message: string) {
export function resolveApiMessage(message: string = '') {
for (let n = 0; n < MESSAGE_MAP.length; ++n) {
const config: ApiMsgConfig = MESSAGE_MAP[n];