Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: qa localisation #489

Merged
merged 16 commits into from
Jan 20, 2025
Prev Previous commit
Next Next commit
chore: fix comments
khanti42 committed Jan 16, 2025
commit 8f5548507ef853ba9bc6d77c2b223acdeafc2739
2 changes: 2 additions & 0 deletions packages/starknet-snap/locales/RULES.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
### Rules for Adding New Fields to the Language File

1. **Key Naming Convention:**

- Use **English text** to derive the key.
- The key should be **camelized** (first word lowercase, subsequent words capitalized).
- Keep the key to **no more than 5 words**.
- If the text in English is **shorter than 5 words**, camelize the entire phrase.
- For **longer text**, use a **concise and meaningful key** (this is a soft constraint).

2. **Dynamic Text Placeholders:**

- Use `{1}`, `{2}`, etc., for dynamic placeholders in messages.
- Example:
- `"visitCompanionDappAndUpgrade": { "message": "Visit the [companion dapp for Starknet]({1}) and click “Upgrade”.\nThank you!" }`
8 changes: 4 additions & 4 deletions packages/starknet-snap/locales/en.json
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@
"amount": {
"message": "Amount"
},
"amountWythSymbol": {
"amountWithSymbol": {
"message": "Amount ({1})"
},
"balance": {
@@ -55,7 +55,7 @@
"compiledClassHash": {
"message": "Compiled Class Hash"
},
"confirmPrivateKeyAction": {
"confirmPrivateKeyToDisplay": {
"message": "Confirming this action will display your private key. Ensure you are in a secure environment."
},
"contract": {
@@ -112,7 +112,7 @@
"signer": {
"message": "Signer"
},
"snapUpdate": {
"snapIsUpToDate": {
"message": "Your Starknet Snap is now up-to-date!"
},
"starknetPrivateKeyConfidential": {
@@ -148,7 +148,7 @@
"visitCompanionDappAndUpgrade": {
"message": "Visit the [companion dapp for Starknet]({1}) and click “Upgrade”.\nThank you!"
},
"walletCompatibility": {
"walletIsCompatible": {
"message": "Your MetaMask wallet is now compatible with Starknet!"
}
}
8 changes: 4 additions & 4 deletions packages/starknet-snap/locales/fr.json
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@
"amount": {
"message": "Montant"
},
"amountWythSymbol": {
"amountWithSymbol": {
"message": "Montant ({1})"
},
"balance": {
@@ -55,7 +55,7 @@
"compiledClassHash": {
"message": "Hash de la classe compilée"
},
"confirmPrivateKeyAction": {
"confirmPrivateKeyToDisplay": {
"message": "Confirmer cette action affichera votre clé privée. Assurez-vous d'être dans un environnement sécurisé."
},
"contract": {
@@ -112,7 +112,7 @@
"signer": {
"message": "Signataire"
},
"snapUpdate": {
"snapIsUpToDate": {
"message": "Votre Starknet Snap est maintenant à jour !"
},
"starknetPrivateKeyConfidential": {
@@ -148,7 +148,7 @@
"visitCompanionDappAndUpgrade": {
"message": "Visitez la [dapp compagnon pour Starknet]({1}) et cliquez sur “Upgrade”.\nMerci !"
},
"walletCompatibility": {
"walletIsCompatible": {
"message": "Votre portefeuille MetaMask est désormais compatible avec Starknet !"
}
}
4 changes: 2 additions & 2 deletions packages/starknet-snap/src/index.tsx
Original file line number Diff line number Diff line change
@@ -303,7 +303,7 @@ export const onInstall: OnInstallHandler = async () => {
const translate = getTranslator();
await ensureJsxSupport(
<Box>
<Text>{translate('walletCompatibility')}</Text>
<Text>{translate('walletIsCompatible')}</Text>
<Text>
{translate('accountManagementIntro')}{' '}
<Link href={getDappUrl()}>{translate('companionDapp')}</Link>.
@@ -317,7 +317,7 @@ export const onUpdate: OnUpdateHandler = async () => {
const translate = getTranslator();
await ensureJsxSupport(
<Box>
<Text>{translate('snapUpdate')}</Text>
<Text>{translate('snapIsUpToDate')}</Text>
<Text>
{translate('accountManagementReminder')}{' '}
<Link href={getDappUrl()}>{translate('companionDapp')}</Link>.
4 changes: 3 additions & 1 deletion packages/starknet-snap/src/signDeployAccountTransaction.ts
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ import type {
ApiParamsWithKeyDeriver,
SignDeployAccountTransactionRequestParams,
} from './types/snapApi';
import { getTranslator } from './utils/locale';
import { logger } from './utils/logger';
import { toJson } from './utils/serializer';
import {
@@ -53,12 +54,13 @@ export async function signDeployAccountTransaction(
);

if (requestParamsObj.enableAuthorize) {
const translate = getTranslator();
const response = await wallet.request({
method: 'snap_dialog',
params: {
type: DialogType.Confirmation,
content: panel([
heading('Do you want to sign this transaction?'),
heading(translate('signTransactionPrompt')),
...snapComponents,
]),
},
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ export const DisplayPrivateKeyDialogUI: SnapComponent = () => {
<Heading>Are you sure you want to reveal your private key?</Heading>
<Box direction="horizontal">
<Icon name="warning" size="md" />
<Text>{translate('confirmPrivateKeyAction')}</Text>
<Text>{translate('confirmPrivateKeyToDisplay')}</Text>
</Box>
</Box>
);
5 changes: 3 additions & 2 deletions packages/starknet-snap/src/upgradeAccContract.ts
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ import type {
} from './types/snapApi';
import { ContractFuncName } from './types/snapState';
import { ACCOUNT_CLASS_HASH, CAIRO_VERSION_LEGACY } from './utils/constants';
import { getTranslator } from './utils/locale';
import { logger } from './utils/logger';
import { toJson } from './utils/serializer';
import {
@@ -105,13 +106,13 @@ export async function upgradeAccContract(params: ApiParamsWithKeyDeriver) {
maxFee,
network,
);

const translate = getTranslator();
const response = await wallet.request({
method: 'snap_dialog',
params: {
type: DialogType.Confirmation,
content: panel([
heading('Do you want to sign this transaction?'),
heading(translate('signTransactionPrompt')),
...dialogComponents,
]),
},
38 changes: 0 additions & 38 deletions packages/starknet-snap/test/src/upgradeAccContract.test.ts
Original file line number Diff line number Diff line change
@@ -153,44 +153,6 @@ describe('Test function: upgradeAccContract', function () {
estimateFeeStub = sandbox.stub(utils, 'estimateFee');
});

it('should use provided max fee to execute txn when max fee provided', async function () {
await loadLocale();
(apiParams.requestParams as UpgradeTransactionRequestParams).maxFee =
'10000';
walletStub.rpcStubs.snap_dialog.resolves(true);
executeTxnStub.resolves(sendTransactionResp);

const address = (
apiParams.requestParams as UpgradeTransactionRequestParams
).contractAddress;
const calldata = CallData.compile({
implementation: ACCOUNT_CLASS_HASH,
calldata: [0],
});

const txnInvocation = {
contractAddress: address,
entrypoint: 'upgrade',
calldata,
};

const result = await upgradeAccContract(apiParams);

expect(executeTxnStub).to.calledOnce;
expect(executeTxnStub).to.calledWith(
STARKNET_SEPOLIA_TESTNET_NETWORK,
address,
'pk',
txnInvocation,
undefined,
{
maxFee: num.toBigInt(10000),
},
CAIRO_VERSION_LEGACY,
);
expect(result).to.be.equal(sendTransactionResp);
});

it('should use calculated max fee to execute txn when max fee not provided', async function () {
await loadLocale();
walletStub.rpcStubs.snap_dialog.resolves(true);