Skip to content

Commit

Permalink
Fix fomrat and remove pre-commit formating
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienbarbier committed Apr 8, 2024
1 parent 28a4ac0 commit 442525a
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx pretty-quick --staged
npx pretty-quick
2 changes: 1 addition & 1 deletion src/app/components/currency/Amount.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function Amount(props) {
string = Math.abs(value)
.toLocaleString(
undefined, // use a string like 'en-US' to override browser locale
{ minimumFractionDigits: digits, maximumFractionDigits: digits },
{ minimumFractionDigits: digits, maximumFractionDigits: digits }
)
.replace(",", "<span>,</span>")
.replace(".", "<span>.</span>");
Expand Down
7 changes: 3 additions & 4 deletions src/app/components/settings/servers/ServerSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ export default function ServerSelector(props) {
setShowAddButton(!props.disableAddAction);
setShowDeleteButton(
servers.find((s) => s.url == selectedServer.url) &&
servers.find((s) => s.url == selectedServer.url).isOfficial ==
undefined,
servers.find((s) => s.url == selectedServer.url).isOfficial == undefined
);
}, [props.disableAddAction, selectedServer, servers]);

Expand All @@ -61,8 +60,8 @@ export default function ServerSelector(props) {
<ServerForm
onSubmit={() => dispatch(AppActions.closeModal())}
onClose={() => dispatch(AppActions.closeModal())}
/>,
),
/>
)
);
};

Expand Down
16 changes: 8 additions & 8 deletions src/app/components/transactions/TransactionList.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,20 @@ export default function TransactionList(props) {
const theme = useTheme();

const categories = useSelector((state) =>
state.categories ? state.categories.list : null,
state.categories ? state.categories.list : null
);
const currencies = useSelector((state) => state.currencies);
const selectedCurrency = useSelector((state) =>
state.currencies && Array.isArray(state.currencies)
? state.currencies.find((c) => c.id === state.account.currency)
: null,
: null
);

const dateFormat = props.dateFormat || "ddd D";

// Pagination
const [pagination, setPagination] = useState(
props.pagination ? parseInt(props.pagination) : null,
props.pagination ? parseInt(props.pagination) : null
);
const more = () => {
setPagination(pagination + parseInt(props.pagination));
Expand Down Expand Up @@ -138,8 +138,8 @@ export default function TransactionList(props) {
transaction={transaction}
onSubmit={() => dispatch(AppActions.closeModal())}
onClose={() => dispatch(AppActions.closeModal())}
/>,
),
/>
)
);
};

Expand Down Expand Up @@ -218,7 +218,7 @@ export default function TransactionList(props) {
<th>
<h3>{moment(key).format(dateFormat)}</h3>
</th>
</tr>,
</tr>
);
}

Expand Down Expand Up @@ -284,7 +284,7 @@ export default function TransactionList(props) {
<Amount
value={item.originalAmount}
currency={currencies.find(
(c) => c.id === item.originalCurrency,
(c) => c.id === item.originalCurrency
)}
/>
) : (
Expand All @@ -302,7 +302,7 @@ export default function TransactionList(props) {
<MoreVertIcon fontSize="small" color="action" />
</IconButton>
</td>
</tr>,
</tr>
);
});

Expand Down
6 changes: 3 additions & 3 deletions src/app/encryption.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,19 @@ const instance = {
},
{ name: "AES-KW" },
true,
["wrapKey", "unwrapKey"],
["wrapKey", "unwrapKey"]
);

instance._key
.then((_) => {
// Init encrypter and decrypter within instance
instance.encrypter = new JoseJWE.Encrypter(
instance.cryptographer,
instance._key,
instance._key
);
instance.decrypter = new JoseJWE.Decrypter(
instance.cryptographer,
instance._key,
instance._key
);
resolve();
})
Expand Down
30 changes: 15 additions & 15 deletions src/app/encryption.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ test("validate encryption and decryption", async () => {

expect(encrypted).toBeTruthy();
expect(encrypted.split(".")[0]).toBe(
"eyJhbGciOiJBMjU2S1ciLCJlbmMiOiJBMTI4Q0JDLUhTMjU2In0",
"eyJhbGciOiJBMjU2S1ciLCJlbmMiOiJBMTI4Q0JDLUhTMjU2In0"
);

const decrypted = await encryption.decrypt(encrypted);
expect(decrypted).toBe("hello");

// Store hardcoded version on the encrypted string to test retrocompatibility with older versions
const decrypted2 = await encryption.decrypt(
"eyJhbGciOiJBMjU2S1ciLCJlbmMiOiJBMTI4Q0JDLUhTMjU2In0.gFG0nz-kyaQxa-rWnUoZEn4RO82QhwqMmFQ5LZhfRzskSFfXoyyTDQ.sb38YunnpeUOrSC57NbalQ.FlWjSvmjYwzALweOD5OGNw.Hsxb-R_mymAkYCzb5ZDSOQ",
"eyJhbGciOiJBMjU2S1ciLCJlbmMiOiJBMTI4Q0JDLUhTMjU2In0.gFG0nz-kyaQxa-rWnUoZEn4RO82QhwqMmFQ5LZhfRzskSFfXoyyTDQ.sb38YunnpeUOrSC57NbalQ.FlWjSvmjYwzALweOD5OGNw.Hsxb-R_mymAkYCzb5ZDSOQ"
);
expect(decrypted2).toBe("hello");
});
Expand All @@ -81,7 +81,7 @@ test("Generate hash from secret", async () => {
const secret = "abc";
const hash = await Jose.crypto.subtle.digest(
{ name: "SHA-256" },
arrayFromString(secret),
arrayFromString(secret)
);
const array = _arrayBufferToBase64(hash);
expect(array).toBe("ungWv48Bz-pBQUDeXa4iI7ADYaOWF3qctBD_YfIAFa0");
Expand All @@ -90,7 +90,7 @@ test("Generate hash from secret", async () => {
const secret2 = "vvV-x_U6bUC-tkCngKY5yDvCmsipgW8fxsXG3Nk8RyE";
const hash2 = await Jose.crypto.subtle.digest(
{ name: "SHA-256" },
arrayFromString(secret2),
arrayFromString(secret2)
);
const array2 = _arrayBufferToBase64(hash2);
expect(array2).toBe("EXVtTcg7qK5d_jsMdokVoYB01ZrXEb46rYNwgEM2TcU");
Expand All @@ -99,7 +99,7 @@ test("Generate hash from secret", async () => {
const secret3 = "vvV-x_U6bUC-tkCngKY5yDvCmsipgW8fxsXG3Nk8RyE";
const hash3 = await crypto.subtle.digest(
{ name: "SHA-256" },
arrayFromString(secret3),
arrayFromString(secret3)
);
const array3 = _arrayBufferToBase64(hash3);
expect(array3).toBe("EXVtTcg7qK5d_jsMdokVoYB01ZrXEb46rYNwgEM2TcU");
Expand All @@ -112,11 +112,11 @@ test("Generate HASH between old and default library", async () => {
const secret = "abc";
const oldHash = await Jose.crypto.subtle.digest(
{ name: "SHA-256" },
arrayFromString(secret),
arrayFromString(secret)
);
var newHash = await crypto.subtle.digest(
{ name: "SHA-256" },
arrayFromString(secret),
arrayFromString(secret)
);
expect(oldHash).toStrictEqual(newHash);

Expand All @@ -141,7 +141,7 @@ test("Generate HASH between old and default library", async () => {
test("Test full decrypt / encrypt", async () => {
var hash = await crypto.subtle.digest(
{ name: "SHA-256" },
arrayFromString("abc"),
arrayFromString("abc")
);

const jwk = {
Expand All @@ -156,7 +156,7 @@ test("Test full decrypt / encrypt", async () => {

const thummbprintUri = await jose.calculateJwkThumbprintUri(jwk);
expect(thummbprintUri).toBe(
"urn:ietf:params:oauth:jwk-thumbprint:sha-256:EyCclB0rJvpqva3jtkQpVcaUuOmeZu_9Q-DMOnmoPWs",
"urn:ietf:params:oauth:jwk-thumbprint:sha-256:EyCclB0rJvpqva3jtkQpVcaUuOmeZu_9Q-DMOnmoPWs"
);
});

Expand All @@ -167,7 +167,7 @@ test("Test hardcoded legacy decoding", async () => {
"eyJhbGciOiJBMjU2S1ciLCJlbmMiOiJBMTI4Q0JDLUhTMjU2In0.gFG0nz-kyaQxa-rWnUoZEn4RO82QhwqMmFQ5LZhfRzskSFfXoyyTDQ.sb38YunnpeUOrSC57NbalQ.FlWjSvmjYwzALweOD5OGNw.Hsxb-R_mymAkYCzb5ZDSOQ";
var hash = await crypto.subtle.digest(
{ name: "SHA-256" },
arrayFromString("abcd"),
arrayFromString("abcd")
);
const cryptoKey = await crypto.subtle.importKey(
"jwk",
Expand All @@ -179,11 +179,11 @@ test("Test hardcoded legacy decoding", async () => {
},
{ name: "AES-KW" },
true, // extractable
["wrapKey", "unwrapKey"], // usages
["wrapKey", "unwrapKey"] // usages
);
const { plaintext } = await jose.compactDecrypt(
oldHardCodedEncrypted,
cryptoKey,
cryptoKey
);
// Plaintext here is an array of string
expect(JSON.parse(new TextDecoder().decode(plaintext))).toBe("hello");
Expand All @@ -208,7 +208,7 @@ test("Test encrypt", async () => {
},
{ name: "AES-KW" },
true, // extractable
["wrapKey", "unwrapKey"], // usages
["wrapKey", "unwrapKey"] // usages
);
// Decrypt
const { plaintext } = await jose.compactDecrypt(oldEncrypted, cryptoKey);
Expand All @@ -233,11 +233,11 @@ test("Test encrypt", async () => {
},
{ name: "AES-KW" },
true, // extractable
["wrapKey", "unwrapKey"], // usages
["wrapKey", "unwrapKey"] // usages
);

const jwe = await new jose.CompactEncrypt(
new TextEncoder().encode(JSON.stringify(stringToEncrypt)), // Encryption in legacy code require stringify json
new TextEncoder().encode(JSON.stringify(stringToEncrypt)) // Encryption in legacy code require stringify json
)
.setProtectedHeader({ alg: "A256KW", enc: "A128CBC-HS256" })
.encrypt(cryptoKey);
Expand Down
2 changes: 1 addition & 1 deletion src/app/utils/currency.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function amountWithCurrencyToString(value, currency, digits = 2) {
// Generate number based on JS .toLocaleString method
string = value.toLocaleString(
undefined, // use a string like 'en-US' to override browser locale
{ minimumFractionDigits: digits, maximumFractionDigits: digits },
{ minimumFractionDigits: digits, maximumFractionDigits: digits }
);

// Add currency sign before of after
Expand Down

0 comments on commit 442525a

Please sign in to comment.