-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
5 additions
and
140 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
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; | ||
}; |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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== | ||
|