From 9edd4e14e932a05875b2ae7cc6da059ac5fe33fe Mon Sep 17 00:00:00 2001 From: Iris Date: Mon, 16 Oct 2023 13:52:29 +0200 Subject: [PATCH] fix: send domain as string to calculate price --- components/domains/renewal.tsx | 3 ++- tests/utils/stringService.test.js | 43 ++++++++++++++++++++++++++++--- utils/stringService.ts | 10 +++++++ 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/components/domains/renewal.tsx b/components/domains/renewal.tsx index 6fc6bd6c..ff7397c4 100644 --- a/components/domains/renewal.tsx +++ b/components/domains/renewal.tsx @@ -11,6 +11,7 @@ import { import { isValidEmail, selectedDomainsToArray, + selectedDomainsToEncodedArray, } from "../../utils/stringService"; import { gweiToEth, applyRateToBigInt } from "../../utils/feltService"; import { Abi, Call } from "starknet"; @@ -171,7 +172,7 @@ const Renewal: FunctionComponent = ({ groups }) => { const calls = [ registrationCalls.approve(price), ...registrationCalls.multiCallRenewal( - selectedDomainsToArray(selectedDomains), + selectedDomainsToEncodedArray(selectedDomains), duration ), ]; diff --git a/tests/utils/stringService.test.js b/tests/utils/stringService.test.js index 1f0f3c8b..3f50650d 100644 --- a/tests/utils/stringService.test.js +++ b/tests/utils/stringService.test.js @@ -24,6 +24,7 @@ import { isValidDomain, getDomainLength, selectedDomainsToArray, + selectedDomainsToEncodedArray } from "../../utils/stringService"; describe("Should test is1234Domain", () => { @@ -413,7 +414,7 @@ describe("Should test getDomainLength function", () => { }); }); -describe("selectedDomainsToArray function", () => { +describe("selectedDomainsToEncodedArray function", () => { it("should return an array of selected domains", () => { const input = { example: true, @@ -426,7 +427,7 @@ describe("selectedDomainsToArray function", () => { encodeDomain("example")[0].toString(), encodeDomain("sample")[0].toString(), ]; - expect(selectedDomainsToArray(input)).toEqual(output); + expect(selectedDomainsToEncodedArray(input)).toEqual(output); }); it("should return an empty array if no domains are selected", () => { @@ -437,7 +438,7 @@ describe("selectedDomainsToArray function", () => { }; const output = []; - expect(selectedDomainsToArray(input)).toEqual(output); + expect(selectedDomainsToEncodedArray(input)).toEqual(output); }); it("should return an array of all domains if all are selected", () => { @@ -452,6 +453,42 @@ describe("selectedDomainsToArray function", () => { encodeDomain("test")[0].toString(), encodeDomain("sample")[0].toString(), ]; + expect(selectedDomainsToEncodedArray(input)).toEqual(output); + }); +}); + +describe("selectedDomainsToArray function", () => { + it("should return an array of selected domains", () => { + const input = { + "example.com": true, + "test.com": false, + "sample.com": true, + "demo.com": false, + }; + + const output = ["example.com", "sample.com"]; + expect(selectedDomainsToArray(input)).toEqual(output); + }); + + it("should return an empty array if no domains are selected", () => { + const input = { + "example.com": false, + "test.com": false, + "sample.com": false, + }; + + const output = []; + expect(selectedDomainsToArray(input)).toEqual(output); + }); + + it("should return an array of all domains if all are selected", () => { + const input = { + "example.com": true, + "test.com": true, + "sample.com": true, + }; + + const output = ["example.com", "test.com", "sample.com"]; expect(selectedDomainsToArray(input)).toEqual(output); }); }); diff --git a/utils/stringService.ts b/utils/stringService.ts index 888efcf2..921436bb 100644 --- a/utils/stringService.ts +++ b/utils/stringService.ts @@ -168,6 +168,16 @@ export function isValidDomain(domain: string | undefined): boolean | string { export function selectedDomainsToArray( selectedDomains: Record +): string[] { + const domainsString: string[] = Object.entries(selectedDomains) + .filter(([, isSelected]) => isSelected) + .map(([domain]) => domain); + + return domainsString; +} + +export function selectedDomainsToEncodedArray( + selectedDomains: Record ): string[] { const domainsString: string[] = Object.entries(selectedDomains) .filter(([, isSelected]) => isSelected)