Skip to content

Instantly share code, notes, and snippets.

@peterpme
Created August 2, 2023 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterpme/a5355e0e08967b3428652841e75b2ec5 to your computer and use it in GitHub Desktop.
Save peterpme/a5355e0e08967b3428652841e75b2ec5 to your computer and use it in GitHub Desktop.
const subtitle =
serverPublicKeys.length === 1
? t('cant_find_recovery_phrase2', {
publicKey: formatWalletAddress(serverPublicKeys[0].publicKey),
})
: t('cant_find_recovery_phrase');
// 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();
}
});
const subtitle =
serverPublicKeys.length === 1 ? (
<Trans
i18nKey='cant_find_recovery_phrase2'
values={{
publicKey: formatWalletAddress(serverPublicKeys[0].publicKey),
}}
/>
) : (
t('cant_find_recovery_phrase')
);
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