Created
August 2, 2023 19:33
-
-
Save peterpme/a5355e0e08967b3428652841e75b2ec5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const subtitle = | |
serverPublicKeys.length === 1 | |
? t('cant_find_recovery_phrase2', { | |
publicKey: formatWalletAddress(serverPublicKeys[0].publicKey), | |
}) | |
: t('cant_find_recovery_phrase'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// DETECT: serverPublicKeys.length === 1 ? (...) : t('cant_find_recovery_phrase') | |
const serverPublicKeyLength = root.find(j.ConditionalExpression, { | |
test: { | |
type: 'BinaryExpression', | |
operator: '===', | |
left: { | |
type: 'MemberExpression', | |
object: { | |
type: 'Identifier', | |
name: 'serverPublicKeys' | |
}, | |
property: { | |
type: 'Identifier', | |
name: 'length' | |
} | |
} | |
} | |
}); | |
// REPLACE: <Trans> with t() | |
serverPublicKeyLength.replaceWith( | |
j.conditionalExpression( | |
serverPublicKeyLength.get('test').node, | |
j.callExpression(j.identifier('t'), [ | |
serverPublicKeyLength.get('consequent', 'body', 0, 'expression', 'arguments', 0).node | |
]), | |
j.callExpression(j.identifier('t'), [ | |
serverPublicKeyLength.get('alternate', 'body', 0, 'expression').node | |
]) | |
) | |
); | |
// ADD: formatWalletAddress(serverPublicKeys[0].publicKey) | |
const serverPublicKeyArgument = serverPublicKeyLength.get( | |
'consequent', 'body', 0, 'expression', 'arguments' | |
); | |
serverPublicKeyArgument.push( | |
j.objectExpression([ | |
j.property( | |
'init', | |
j.identifier('publicKey'), | |
j.callExpression( | |
j.identifier('formatWalletAddress'), | |
[ | |
j.memberExpression( | |
j.memberExpression( | |
j.identifier('serverPublicKeys'), | |
j.numericLiteral(0), | |
true | |
), | |
j.identifier('publicKey'), | |
false | |
) | |
] | |
) | |
) | |
]) | |
); | |
// REMOVE: <Trans> | |
serverPublicKeyLength.get('consequent', 'body').forEach((statement) => { | |
if (statement.type === 'JSXElement') { | |
statement.remove(); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const subtitle = | |
serverPublicKeys.length === 1 ? ( | |
<Trans | |
i18nKey='cant_find_recovery_phrase2' | |
values={{ | |
publicKey: formatWalletAddress(serverPublicKeys[0].publicKey), | |
}} | |
/> | |
) : ( | |
t('cant_find_recovery_phrase') | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const subtitle = | |
serverPublicKeys.length === 1 ? ( | |
<Trans | |
i18nKey='cant_find_recovery_phrase2' | |
values={{ | |
publicKey: formatWalletAddress(serverPublicKeys[0].publicKey), | |
}} | |
/> | |
) : ( | |
t('cant_find_recovery_phrase') | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment