Skip to content

Commit

Permalink
redesign: add bank code selection to bank_account kyc flows
Browse files Browse the repository at this point in the history
  • Loading branch information
tams sokari committed Oct 12, 2023
1 parent a64dfb2 commit 7f90597
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/basic-kyc.html
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,19 @@ <h1 class="center">Enter ID Information</h1>
</p>

<form name="user-details" class="flow">
<fieldset hidden id='bank-code' data-variant='start'>
<label class="required" for="bank_code"> Bank </label>

<select
aria-required="true"
name="bank_code"
id="bank_code"
required
>
<option key="" value="">--Select Bank--</option>
</select>
</fieldset>

<div hidden id="id-number" class="input-group flow">
<label class="required" for="id_number"> ID Number </label>

Expand Down
13 changes: 13 additions & 0 deletions src/ekyc.html
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,19 @@ <h1 class="center">Enter ID Information</h1>
</p>

<form name="user-details" class="flow">
<fieldset hidden id='bank-code' data-variant='start'>
<label class="required" for="bank_code"> Bank </label>

<select
aria-required="true"
name="bank_code"
id="bank_code"
required
>
<option key="" value="">--Select Bank--</option>
</select>
</fieldset>

<div hidden id="id-number" class="input-group flow">
<label class="required" for="id_number"> ID Number </label>

Expand Down
66 changes: 65 additions & 1 deletion src/js/basic-kyc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import validate from "validate.js";
import ConsentScreen from "./components/ConsentScreen";
import TotpBasedConsent from "./components/TotpConsentApp";
import Combobox from './components/Combobox';

Check failure on line 4 in src/js/basic-kyc.js

View workflow job for this annotation

GitHub Actions / lint

Replace `'./components/Combobox'` with `"./components/Combobox"`
import { version as sdkVersion } from "../../package.json";

(function basicKyc() {
Expand All @@ -21,12 +22,18 @@ import { version as sdkVersion } from "../../package.json";
window.customElements.define("end-user-consent", ConsentScreen);
window.customElements.define("totp-consent-app", TotpBasedConsent);

window.customElements.define("smileid-combobox", Combobox.Root);
window.customElements.define("smileid-combobox-trigger", Combobox.Trigger);
window.customElements.define("smileid-combobox-listbox", Combobox.List);
window.customElements.define("smileid-combobox-option", Combobox.Option);

const pages = [];
let activeScreen;
let config;
let consent_information;
let id_info;
let partner_params;
let ngBankCodes;
let productConstraints;
let EndUserConsent;

Expand Down Expand Up @@ -77,6 +84,7 @@ import { version as sdkVersion } from "../../package.json";
if (productsConfigResponse.ok && servicesResponse.ok) {
const partnerConstraints = await productsConfigResponse.json();
const generalConstraints = await servicesResponse.json();
ngBankCodes = generalConstraints.bank_codes;

const previewBvnMfa = config.previewBVNMFA;
if (previewBvnMfa) {
Expand Down Expand Up @@ -124,6 +132,7 @@ import { version as sdkVersion } from "../../package.json";
false,
);

Check failure on line 133 in src/js/basic-kyc.js

View workflow job for this annotation

GitHub Actions / lint

Delete `⏎`


function setInitialScreen(partnerConstraints) {
const { country: selectedCountry, id_type: selectedIDType } = id_info;

Expand Down Expand Up @@ -466,6 +475,38 @@ import { version as sdkVersion } from "../../package.json";
);
}

function loadBankCodes(bankCodes, placeholderElement) {
const autocomplete = document.createElement("smileid-combobox");
autocomplete.setAttribute("id", "bank_code");
autocomplete.innerHTML = `
<smileid-combobox-trigger
label="Search Bank">
</smileid-combobox-trigger>
<smileid-combobox-listbox empty-label="No bank found">
${bankCodes
.map(
(bank) =>
`
<smileid-combobox-option
value="${bank.code}"
label="${bank.name}"
>
${bank.name}
</smileid-combobox-option>
`,
)
.join("\n")}
</smileid-combobox-listbox>
`;
placeholderElement.replaceWith(autocomplete);
autocomplete.addEventListener('change', (e) => {

Check failure on line 503 in src/js/basic-kyc.js

View workflow job for this annotation

GitHub Actions / lint

Replace `'change'` with `"change"`
id_info.bank_code = e.detail ? e.detail.value : '';

Check failure on line 504 in src/js/basic-kyc.js

View workflow job for this annotation

GitHub Actions / lint

Replace `''` with `""`
});

return autocomplete;
}

function setFormInputs() {
const requiredFields =
productConstraints[id_info.country].id_types[id_info.id_type]
Expand Down Expand Up @@ -506,6 +547,16 @@ import { version as sdkVersion } from "../../package.json";
const Citizenship = IDInfoForm.querySelector("fieldset#citizenships");
Citizenship.hidden = false;
}

const showBankCode = requiredFields.some((fieldName) =>
fieldName.includes("bank_code"),
);

if (showBankCode) {
const BankCode = IDInfoForm.querySelector("fieldset#bank-code");
loadBankCodes(ngBankCodes, BankCode.querySelector('#bank_code'));

Check failure on line 557 in src/js/basic-kyc.js

View workflow job for this annotation

GitHub Actions / lint

Replace `'#bank_code'` with `"#bank_code"`
BankCode.hidden = false;
}
}

function getPartnerParams() {
Expand Down Expand Up @@ -638,6 +689,19 @@ import { version as sdkVersion } from "../../package.json";
};
}

const showBankCode = requiredFields.some((fieldName) =>
fieldName.includes("bank_code"),
);

if (showBankCode) {
validationConstraints.bank_code = {
presence: {
allowEmpty: false,
message: "is required",
},
};
}

const validation = validate(payload, validationConstraints);

if (validation) {
Expand Down Expand Up @@ -672,7 +736,7 @@ import { version as sdkVersion } from "../../package.json";
const form = IDInfoForm.querySelector("form");

const formData = new FormData(form);
const payload = Object.fromEntries(formData.entries());
const payload = Object.assign({}, id_info, Object.fromEntries(formData.entries()));

Check failure on line 739 in src/js/basic-kyc.js

View workflow job for this annotation

GitHub Actions / lint

Use an object spread instead of `Object.assign` eg: `{ ...foo }`

Check failure on line 739 in src/js/basic-kyc.js

View workflow job for this annotation

GitHub Actions / lint

Replace `{},·id_info,·Object.fromEntries(formData.entries())` with `⏎······{},⏎······id_info,⏎······Object.fromEntries(formData.entries()),⏎····`

const isInvalid = validateInputs(payload);

Expand Down
59 changes: 58 additions & 1 deletion src/js/ekyc.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { version as sdkVersion } from "../../package.json";
let EndUserConsent;
let id_info;
let partner_params;
let ngBankCodes;
let productConstraints;

const LoadingScreen = document.querySelector("#loading-screen");
Expand Down Expand Up @@ -76,6 +77,7 @@ import { version as sdkVersion } from "../../package.json";
if (productsConfigResponse.ok && servicesResponse.ok) {
const partnerConstraints = await productsConfigResponse.json();
const generalConstraints = await servicesResponse.json();
ngBankCodes = generalConstraints.bank_codes;

const previewBvnMfa = config.previewBVNMFA;
if (previewBvnMfa) {
Expand Down Expand Up @@ -465,6 +467,38 @@ import { version as sdkVersion } from "../../package.json";
);
}

function loadBankCodes(bankCodes, placeholderElement) {
const autocomplete = document.createElement("smileid-combobox");
autocomplete.setAttribute("id", "bank_code");
autocomplete.innerHTML = `
<smileid-combobox-trigger
label="Search Bank">
</smileid-combobox-trigger>
<smileid-combobox-listbox empty-label="No bank found">
${bankCodes
.map(
(bank) =>
`
<smileid-combobox-option
value="${bank.code}"
label="${bank.name}"
>
${bank.name}
</smileid-combobox-option>
`,
)
.join("\n")}
</smileid-combobox-listbox>
`;
placeholderElement.replaceWith(autocomplete);
autocomplete.addEventListener('change', (e) => {

Check failure on line 495 in src/js/ekyc.js

View workflow job for this annotation

GitHub Actions / lint

Replace `'change'` with `"change"`
id_info.bank_code = e.detail ? e.detail.value : '';

Check failure on line 496 in src/js/ekyc.js

View workflow job for this annotation

GitHub Actions / lint

Replace `''` with `""`
});

return autocomplete;
}

function setFormInputs() {
const requiredFields =
productConstraints[id_info.country].id_types[id_info.id_type]
Expand Down Expand Up @@ -505,6 +539,16 @@ import { version as sdkVersion } from "../../package.json";
const Citizenship = IDInfoForm.querySelector("fieldset#citizenships");
Citizenship.hidden = false;
}

const showBankCode = requiredFields.some((fieldName) =>
fieldName.includes("bank_code"),
);

if (showBankCode) {
const BankCode = IDInfoForm.querySelector("fieldset#bank-code");
loadBankCodes(ngBankCodes, BankCode.querySelector('#bank_code'));

Check failure on line 549 in src/js/ekyc.js

View workflow job for this annotation

GitHub Actions / lint

Replace `'#bank_code'` with `"#bank_code"`
BankCode.hidden = false;
}
}

function getPartnerParams() {
Expand Down Expand Up @@ -637,6 +681,19 @@ import { version as sdkVersion } from "../../package.json";
};
}

const showBankCode = requiredFields.some((fieldName) =>
fieldName.includes("bank_code"),
);

if (showBankCode) {
validationConstraints.bank_code = {
presence: {
allowEmpty: false,
message: "is required",
},
};
}

const validation = validate(payload, validationConstraints);

if (validation) {
Expand Down Expand Up @@ -673,7 +730,7 @@ import { version as sdkVersion } from "../../package.json";
const form = IDInfoForm.querySelector("form");

const formData = new FormData(form);
const payload = Object.fromEntries(formData.entries());
const payload = Object.assign({}, id_info, Object.fromEntries(formData.entries()));

const isInvalid = validateInputs(payload);

Expand Down

0 comments on commit 7f90597

Please sign in to comment.