Skip to content

Commit

Permalink
Remove deadcode (#407)
Browse files Browse the repository at this point in the history
  • Loading branch information
zoontek authored Oct 25, 2023
1 parent f4b08e5 commit a3e0676
Show file tree
Hide file tree
Showing 10 changed files with 5 additions and 140 deletions.
1 change: 0 additions & 1 deletion LICENSE_REPORT.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ nanoid | 5.0.2 | MIT | https://github.com/ai/nanoid.git | Unknown | Andrey Sitni
node-mailjet | 6.0.4 | MIT | https://github.com/mailjet/mailjet-apiv3-nodejs.git | https://github.com/mailjet/mailjet-apiv3-nodejs#readme | Mailjet
pathe | 1.1.1 | MIT | https://github.com/unjs/pathe.git | Unknown | Unknown
pino-pretty | 10.2.3 | MIT | ssh://[email protected]/pinojs/pino-pretty.git | https://github.com/pinojs/pino-pretty#readme | James Sumners
polished | 4.2.2 | MIT | https://github.com/styled-components/polished.git | https://polished.js.org/ | Brian Hough
react | 18.2.0 | MIT | https://github.com/facebook/react.git | https://reactjs.org/ | Unknown
react-atomic-state | 1.2.7 | MIT | https://github.com/zoontek/react-atomic-state.git | https://github.com/zoontek/react-atomic-state#readme | Mathieu Acthernoene
react-dom | 18.2.0 | MIT | https://github.com/facebook/react.git | https://reactjs.org/ | Unknown
Expand Down
3 changes: 0 additions & 3 deletions clients/banking/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"iban": "0.0.14",
"libphonenumber-js": "1.10.48",
"nanoid": "5.0.2",
"polished": "4.2.2",
"react": "18.2.0",
"react-atomic-state": "1.2.7",
"react-dom": "18.2.0",
Expand All @@ -44,8 +43,6 @@
"wonka": "6.3.4"
},
"devDependencies": {
"@testing-library/react": "14.0.0",
"@testing-library/user-event": "14.5.1",
"@types/iban": "0.0.34",
"@types/react": "18.2.31",
"@types/react-dom": "18.2.14",
Expand Down
33 changes: 0 additions & 33 deletions clients/banking/src/components/FormText.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion clients/banking/src/components/TransactionListCells.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export const TransactionNameCell = ({ transaction }: { transaction: Transaction
);
};

export const formatTransactionType = (typename: string) => {
const formatTransactionType = (typename: string) => {
const unprefixed = typename.startsWith("SEPA") ? typename.slice(4) : typename;

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ const styles = StyleSheet.create({
},
});

export type FixedAmountDetails = {
type FixedAmountDetails = {
type: "FixedAmount";
amount: PaymentCurrencyAmount;
label?: string;
reference?: string;
};

export type TargetAccountBalanceDetails = {
type TargetAccountBalanceDetails = {
type: "TargetAccountBalance";
targetAmount: PaymentCurrencyAmount;
label?: string;
Expand Down
10 changes: 0 additions & 10 deletions clients/banking/src/utils/date.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
import dayjs from "dayjs";
import { locale } from "./i18n";

export const decodeDate = (value: string) => {
const date = dayjs.utc(value, "YYYY-MM-DD");
return date.isValid() ? date.format(locale.dateFormat) : "";
};

export const encodeDate = (value: string) => {
const date = dayjs.utc(value, locale.dateFormat);
return date.isValid() ? date.format("YYYY-MM-DD") : "";
};

export const encodeDateTime = (date: string, time: string) => {
const dateTime = dayjs(`${date} ${time}`, `${locale.dateFormat} ${locale.timeFormat}`);
return dateTime.isValid() ? dateTime.toISOString() : "";
Expand Down
54 changes: 1 addition & 53 deletions clients/banking/src/utils/iban.ts
Original file line number Diff line number Diff line change
@@ -1,61 +1,9 @@
import { Result } from "@swan-io/boxed";
import { parseOperationResult } from "@swan-io/lake/src/utils/urql";
import { isValid as isValidIban } from "iban";
import { match, P } from "ts-pattern";
import { Client } from "urql";
import { GetIbanValidationDocument, ValidIbanInformationFragment } from "../graphql/partner";
import { t } from "./i18n";
export { isValid as isValidIban, printFormat as printIbanFormat } from "iban";
export { printFormat as printIbanFormat } from "iban";

export const validateIban = (iban: string) => {
if (!isValidIban(iban)) {
return t("error.iban.invalid");
}
};

// Cache already validated IBANs to avoid backend call on submit
const alreadyValidatedIbans: Record<string, ValidIbanInformationFragment> = {};

export const getIbanValidation = async (client: Client, iban: string) => {
const ibanWithoutSpaces = iban.replace(/ /g, "");

// If we already validated the IBAN, we return the cached result
const cachedValidation = alreadyValidatedIbans[ibanWithoutSpaces];
if (cachedValidation) {
return Result.Ok(cachedValidation);
}

const result = (
await Result.fromPromise(
client
.query(GetIbanValidationDocument, { iban: ibanWithoutSpaces })
.toPromise()
.then(parseOperationResult),
)
)
.mapError(() => "NoIbanValidation" as const)
.flatMap(({ ibanValidation }) =>
match(ibanValidation)
.with(P.nullish, () => Result.Error("NoIbanValidation" as const))
.with({ __typename: "InvalidIban" }, ({ code }) => Result.Error(code))
.with({ __typename: "ValidIban" }, validation => {
alreadyValidatedIbans[ibanWithoutSpaces] = validation;
return Result.Ok(validation);
})
.exhaustive(),
)
.mapError(error =>
match(error)
.with("InvalidLength", "InvalidStructure", "InvalidChecksum", () => t("error.iban.invalid"))
.with("InvalidBank", () => t("error.iban.invalidBank"))
.with("NoIbanValidation", () => {
// If we failed to validate the IBAN with backend, we do local validation
if (!isValidIban(iban)) {
return t("error.iban.invalid");
}
})
.exhaustive(),
);

return result;
};
5 changes: 0 additions & 5 deletions clients/banking/src/utils/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,6 @@ export const accountTransactionsRoutes = [
"AccountTransactionsUpcoming",
] as const;

export const accountTransactionsStatementsRoutes = [
"AccountTransactionsListStatementsMonthly",
"AccountTransactionsListStatementsUpcoming",
];

export const membershipsRoutes = ["AccountMembersList", "AccountMembersDetailsArea"] as const;

export const membershipsDetailRoutes = [
Expand Down
31 changes: 0 additions & 31 deletions clients/banking/src/utils/validations.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Lazy } from "@swan-io/boxed";
import { DatePickerDate } from "@swan-io/shared-business/src/components/DatePicker";
import { isValidVatNumber } from "@swan-io/shared-business/src/utils/validation";
import dayjs from "dayjs";
Expand Down Expand Up @@ -150,22 +149,6 @@ export const validateAddressLine: Validator<string> = value => {
}
};

export const REFERENCE_MAX_LENGTH = 35;

export const validateReference: Validator<string> = value => {
const hasOnlyLatinChars = /^[\w/\-?:().,’+ ]*$/.test(value);
const hasDoubleSlash = value.includes("//");
const startOrEndWithSlash = [value[0], value[value.length - 1]].includes("/");

if (value !== "" && (!hasOnlyLatinChars || hasDoubleSlash || startOrEndWithSlash)) {
return t("error.transferReferenceInvalid");
}

if (value !== "" && value.length > REFERENCE_MAX_LENGTH) {
return t("error.transferReferenceTooLong");
}
};

export const validateVatNumber: Validator<string> = value => {
const cleaned = value.replace(/[^A-Z0-9]/gi, "");
if (cleaned.length === 0) {
Expand All @@ -177,20 +160,6 @@ export const validateVatNumber: Validator<string> = value => {
}
};

// Whitelisting the first 8 blocks of unicode (the 9th being cyrilic)
// And then whitelisting General punctuation, mathematical notations and emojis
// For reference : https://jrgraphix.net/r/Unicode/
const VALID_SEPA_BENEFICIARY_NAME_ALPHABET = Lazy(
() =>
/^([\u0020-\u03FF\u2200-\u22FF\u2000-\u206F]|(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff]))+$/,
);

export const validateSepaBeneficiaryNameAlphabet: Validator<string> = value => {
if (!VALID_SEPA_BENEFICIARY_NAME_ALPHABET.get().test(value)) {
return t("error.beneficiaryNameInvalid");
}
};

export const isAfterUpdatedAtSelectable = (date: DatePickerDate, filters: unknown) => {
return match(filters)
.with({ isBeforeUpdatedAt: P.string }, ({ isBeforeUpdatedAt }) => {
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6937,7 +6937,7 @@ [email protected]:
optionalDependencies:
fsevents "2.3.2"

polished@4.2.2, polished@^4.2.2:
polished@^4.2.2:
version "4.2.2"
resolved "https://registry.yarnpkg.com/polished/-/polished-4.2.2.tgz#2529bb7c3198945373c52e34618c8fe7b1aa84d1"
integrity sha512-Sz2Lkdxz6F2Pgnpi9U5Ng/WdWAUZxmHrNPoVlm3aAemxoy2Qy7LGjQg4uf8qKelDAUW94F4np3iH2YPf2qefcQ==
Expand Down

0 comments on commit a3e0676

Please sign in to comment.