Skip to content

Commit

Permalink
Merge pull request #447 from starknet-id/fix/renewal_domain_price
Browse files Browse the repository at this point in the history
  • Loading branch information
fricoben authored Oct 16, 2023
2 parents c766535 + 9edd4e1 commit b748bac
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
3 changes: 2 additions & 1 deletion components/domains/renewal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import {
isValidEmail,
selectedDomainsToArray,
selectedDomainsToEncodedArray,
} from "../../utils/stringService";
import { gweiToEth, applyRateToBigInt } from "../../utils/feltService";
import { Abi, Call } from "starknet";
Expand Down Expand Up @@ -171,7 +172,7 @@ const Renewal: FunctionComponent<RenewalProps> = ({ groups }) => {
const calls = [
registrationCalls.approve(price),
...registrationCalls.multiCallRenewal(
selectedDomainsToArray(selectedDomains),
selectedDomainsToEncodedArray(selectedDomains),
duration
),
];
Expand Down
43 changes: 40 additions & 3 deletions tests/utils/stringService.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
isValidDomain,
getDomainLength,
selectedDomainsToArray,
selectedDomainsToEncodedArray
} from "../../utils/stringService";

describe("Should test is1234Domain", () => {
Expand Down Expand Up @@ -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,
Expand All @@ -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", () => {
Expand All @@ -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", () => {
Expand All @@ -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);
});
});
10 changes: 10 additions & 0 deletions utils/stringService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,16 @@ export function isValidDomain(domain: string | undefined): boolean | string {

export function selectedDomainsToArray(
selectedDomains: Record<string, boolean>
): string[] {
const domainsString: string[] = Object.entries(selectedDomains)
.filter(([, isSelected]) => isSelected)
.map(([domain]) => domain);

return domainsString;
}

export function selectedDomainsToEncodedArray(
selectedDomains: Record<string, boolean>
): string[] {
const domainsString: string[] = Object.entries(selectedDomains)
.filter(([, isSelected]) => isSelected)
Expand Down

2 comments on commit b748bac

@vercel
Copy link

@vercel vercel bot commented on b748bac Oct 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on b748bac Oct 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.