Skip to content

Commit

Permalink
feat: add recurrent fees on LOC creation.
Browse files Browse the repository at this point in the history
  • Loading branch information
gdethier committed Nov 7, 2023
1 parent bf42d08 commit f445ffe
Show file tree
Hide file tree
Showing 11 changed files with 206 additions and 14 deletions.
6 changes: 6 additions & 0 deletions src/__mocks__/LogionMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export const CLOSED_IDENTITY_LOC: LegalOfficerCase = {
links: [],
collectionCanUpload: false,
valueFee: 0n,
collectionItemFee: 0n,
tokensRecordFee: 0n,
}

export const OPEN_IDENTITY_LOC_ID = "195914524858768213081425411950368569411";
Expand All @@ -82,6 +84,8 @@ export const OPEN_IDENTITY_LOC: LegalOfficerCase = {
links: [],
collectionCanUpload: false,
valueFee: 0n,
collectionItemFee: 0n,
tokensRecordFee: 0n,
}

export const CLOSED_COLLECTION_LOC_ID = "195914524858768213081425411950368569411";
Expand All @@ -96,4 +100,6 @@ export const CLOSED_COLLECTION_LOC: LegalOfficerCase = {
links: [],
collectionCanUpload: false,
valueFee: 100n,
collectionItemFee: 50n,
tokensRecordFee: 40n,
}
10 changes: 9 additions & 1 deletion src/components/identity/CollectionInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@ export function CollectionInfo(props: Props) {
<Col>
<Detail label="Value fee" value={ <span>
<AmountFormat amount={
props.collection.valueFee ? toPrefixedLgnt(props.collection.valueFee.toString()) : Currency.nLgnt(0n)
props.collection.fees.valueFee ? toPrefixedLgnt(props.collection.fees.valueFee.toString()) : Currency.nLgnt(0n)
}/> { Currency.SYMBOL }</span> } />
<Detail label="Collection item fee" value={ <span>
<AmountFormat amount={
props.collection.fees.collectionItemFee ? toPrefixedLgnt(props.collection.fees.collectionItemFee.toString()) : Currency.nLgnt(0n)
}/> { Currency.SYMBOL }</span> } />
<Detail label="Tokens record fee" value={ <span>
<AmountFormat amount={
props.collection.fees.tokensRecordFee ? toPrefixedLgnt(props.collection.fees.tokensRecordFee.toString()) : Currency.nLgnt(0n)
}/> { Currency.SYMBOL }</span> } />
</Col>
<Col>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe("LocRequestAcceptance", () => {

setupApiMock(api => {
const submittable = mockSubmittable();
api.setup(instance => instance.polkadot.tx.logionLoc.createCollectionLoc(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), null, It.IsAny())).returns(submittable.object());
api.setup(instance => instance.polkadot.tx.logionLoc.createCollectionLoc(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), null, It.IsAny(), It.IsAny(), It.IsAny())).returns(submittable.object());
const fees = new Mock<Fees>();
api.setup(instance => instance.fees.estimateCreateLoc(It.IsAny())).returnsAsync(fees.object());
});
Expand Down
4 changes: 2 additions & 2 deletions src/loc/LegalFeeAmount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export default function LegalFeeAmount(props: Props) {
if(props.loc.requesterLocId) {
return { value: 0n, custom: true };
} else {
if(props.loc.legalFee !== undefined) {
return { value: props.loc.legalFee, custom: true };
if(props.loc.fees.legalFee !== undefined) {
return { value: props.loc.fees.legalFee, custom: true };
} else {
return { value: Currency.toCanonicalAmount(Currency.nLgnt(DEFAULT_LEGAL_FEE)), custom: false };
}
Expand Down
9 changes: 8 additions & 1 deletion src/loc/OpenLoc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,17 @@ export default function OpenLoc(props: Props) {
(async function () {
if (locState instanceof AcceptedRequest) {
if (locState.data().locType === "Collection") {
const apiLimits = await limits.toApiLimits(client.logionApi)
const apiLimits = await limits.toApiLimits(client.logionApi);
const fees = locState.data().fees;
if(fees.valueFee === undefined || fees.collectionItemFee === undefined || fees.tokensRecordFee === undefined) {
throw new Error("Value or recurrent fees missing");
}
setFees(await locState.estimateFeesOpenCollection({
...apiLimits,
autoPublish,
valueFee: fees.valueFee,
collectionItemFee: fees.collectionItemFee,
tokensRecordFee: fees.tokensRecordFee,
}));
} else {
setFees(await locState.estimateFeesOpen({ autoPublish }));
Expand Down
6 changes: 6 additions & 0 deletions src/loc/TestData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,11 @@ export function buildLocRequest(locId: UUID, loc: LegalOfficerCase): LocData {
})),
verifiedIssuer: false,
issuers: [],
fees: {
valueFee: loc.valueFee,
legalFee: loc.legalFee,
collectionItemFee: loc.collectionItemFee,
tokensRecordFee: loc.tokensRecordFee,
}
};
}
42 changes: 42 additions & 0 deletions src/loc/__snapshots__/ContextualizedLocDetails.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ exports[`ContextualizedLocDetails renders 1`] = `
"createdOn": "2023-10-10T08:25:18.546Z",
"decisionOn": "2023-10-10T08:25:18.546Z",
"description": "Description",
"fees": Object {
"collectionItemFee": 0n,
"legalFee": undefined,
"tokensRecordFee": 0n,
"valueFee": 0n,
},
"files": Array [],
"id": UUID {
"bytes": Array [
Expand Down Expand Up @@ -51,6 +57,12 @@ exports[`ContextualizedLocDetails renders 1`] = `
"createdOn": "2023-10-10T08:25:18.546Z",
"decisionOn": "2023-10-10T08:25:18.546Z",
"description": "Description",
"fees": Object {
"collectionItemFee": 0n,
"legalFee": undefined,
"tokensRecordFee": 0n,
"valueFee": 0n,
},
"files": Array [],
"id": UUID {
"bytes": Array [
Expand Down Expand Up @@ -107,6 +119,12 @@ exports[`ContextualizedLocDetails renders 1`] = `
"createdOn": "2023-10-10T08:25:18.546Z",
"decisionOn": "2023-10-10T08:25:18.546Z",
"description": "Description",
"fees": Object {
"collectionItemFee": 0n,
"legalFee": undefined,
"tokensRecordFee": 0n,
"valueFee": 0n,
},
"files": Array [],
"id": UUID {
"bytes": Array [
Expand Down Expand Up @@ -159,6 +177,12 @@ exports[`ContextualizedLocDetails renders 1`] = `
"createdOn": "2023-10-10T08:25:18.546Z",
"decisionOn": "2023-10-10T08:25:18.546Z",
"description": "Description",
"fees": Object {
"collectionItemFee": 0n,
"legalFee": undefined,
"tokensRecordFee": 0n,
"valueFee": 0n,
},
"files": Array [],
"id": UUID {
"bytes": Array [
Expand Down Expand Up @@ -204,6 +228,12 @@ exports[`ContextualizedLocDetails renders 1`] = `
"createdOn": "2023-10-10T08:25:18.546Z",
"decisionOn": "2023-10-10T08:25:18.546Z",
"description": "Description",
"fees": Object {
"collectionItemFee": 0n,
"legalFee": undefined,
"tokensRecordFee": 0n,
"valueFee": 0n,
},
"files": Array [],
"id": UUID {
"bytes": Array [
Expand Down Expand Up @@ -249,6 +279,12 @@ exports[`ContextualizedLocDetails renders 1`] = `
"createdOn": "2023-10-10T08:25:18.546Z",
"decisionOn": "2023-10-10T08:25:18.546Z",
"description": "Description",
"fees": Object {
"collectionItemFee": 0n,
"legalFee": undefined,
"tokensRecordFee": 0n,
"valueFee": 0n,
},
"files": Array [],
"id": UUID {
"bytes": Array [
Expand Down Expand Up @@ -298,6 +334,12 @@ exports[`ContextualizedLocDetails renders 1`] = `
"createdOn": "2023-10-10T08:25:18.546Z",
"decisionOn": "2023-10-10T08:25:18.546Z",
"description": "Description",
"fees": Object {
"collectionItemFee": 0n,
"legalFee": undefined,
"tokensRecordFee": 0n,
"valueFee": 0n,
},
"files": Array [],
"id": UUID {
"bytes": Array [
Expand Down
60 changes: 60 additions & 0 deletions src/loc/__snapshots__/UserContextualizedLocDetails.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ exports[`UserContextualizedLocDetails renders for requester 1`] = `
"createdOn": "2023-10-10T08:25:18.546Z",
"decisionOn": "2023-10-10T08:25:18.546Z",
"description": "Description",
"fees": Object {
"collectionItemFee": 0n,
"legalFee": undefined,
"tokensRecordFee": 0n,
"valueFee": 0n,
},
"files": Array [],
"id": UUID {
"bytes": Array [
Expand Down Expand Up @@ -82,6 +88,12 @@ exports[`UserContextualizedLocDetails renders for requester 1`] = `
"createdOn": "2023-10-10T08:25:18.546Z",
"decisionOn": "2023-10-10T08:25:18.546Z",
"description": "Description",
"fees": Object {
"collectionItemFee": 0n,
"legalFee": undefined,
"tokensRecordFee": 0n,
"valueFee": 0n,
},
"files": Array [],
"id": UUID {
"bytes": Array [
Expand Down Expand Up @@ -129,6 +141,12 @@ exports[`UserContextualizedLocDetails renders for requester 1`] = `
"createdOn": "2023-10-10T08:25:18.546Z",
"decisionOn": "2023-10-10T08:25:18.546Z",
"description": "Description",
"fees": Object {
"collectionItemFee": 0n,
"legalFee": undefined,
"tokensRecordFee": 0n,
"valueFee": 0n,
},
"files": Array [],
"id": UUID {
"bytes": Array [
Expand Down Expand Up @@ -175,6 +193,12 @@ exports[`UserContextualizedLocDetails renders for requester 1`] = `
"createdOn": "2023-10-10T08:25:18.546Z",
"decisionOn": "2023-10-10T08:25:18.546Z",
"description": "Description",
"fees": Object {
"collectionItemFee": 0n,
"legalFee": undefined,
"tokensRecordFee": 0n,
"valueFee": 0n,
},
"files": Array [],
"id": UUID {
"bytes": Array [
Expand Down Expand Up @@ -220,6 +244,12 @@ exports[`UserContextualizedLocDetails renders for requester 1`] = `
"createdOn": "2023-10-10T08:25:18.546Z",
"decisionOn": "2023-10-10T08:25:18.546Z",
"description": "Description",
"fees": Object {
"collectionItemFee": 0n,
"legalFee": undefined,
"tokensRecordFee": 0n,
"valueFee": 0n,
},
"files": Array [],
"id": UUID {
"bytes": Array [
Expand Down Expand Up @@ -275,6 +305,12 @@ exports[`UserContextualizedLocDetails renders for verified issuer 1`] = `
"createdOn": "2023-10-10T08:25:18.546Z",
"decisionOn": "2023-10-10T08:25:18.546Z",
"description": "Description",
"fees": Object {
"collectionItemFee": 0n,
"legalFee": undefined,
"tokensRecordFee": 0n,
"valueFee": 0n,
},
"files": Array [],
"id": UUID {
"bytes": Array [
Expand Down Expand Up @@ -350,6 +386,12 @@ exports[`UserContextualizedLocDetails renders for verified issuer 1`] = `
"createdOn": "2023-10-10T08:25:18.546Z",
"decisionOn": "2023-10-10T08:25:18.546Z",
"description": "Description",
"fees": Object {
"collectionItemFee": 0n,
"legalFee": undefined,
"tokensRecordFee": 0n,
"valueFee": 0n,
},
"files": Array [],
"id": UUID {
"bytes": Array [
Expand Down Expand Up @@ -397,6 +439,12 @@ exports[`UserContextualizedLocDetails renders for verified issuer 1`] = `
"createdOn": "2023-10-10T08:25:18.546Z",
"decisionOn": "2023-10-10T08:25:18.546Z",
"description": "Description",
"fees": Object {
"collectionItemFee": 0n,
"legalFee": undefined,
"tokensRecordFee": 0n,
"valueFee": 0n,
},
"files": Array [],
"id": UUID {
"bytes": Array [
Expand Down Expand Up @@ -443,6 +491,12 @@ exports[`UserContextualizedLocDetails renders for verified issuer 1`] = `
"createdOn": "2023-10-10T08:25:18.546Z",
"decisionOn": "2023-10-10T08:25:18.546Z",
"description": "Description",
"fees": Object {
"collectionItemFee": 0n,
"legalFee": undefined,
"tokensRecordFee": 0n,
"valueFee": 0n,
},
"files": Array [],
"id": UUID {
"bytes": Array [
Expand Down Expand Up @@ -488,6 +542,12 @@ exports[`UserContextualizedLocDetails renders for verified issuer 1`] = `
"createdOn": "2023-10-10T08:25:18.546Z",
"decisionOn": "2023-10-10T08:25:18.546Z",
"description": "Description",
"fees": Object {
"collectionItemFee": 0n,
"legalFee": undefined,
"tokensRecordFee": 0n,
"valueFee": 0n,
},
"files": Array [],
"id": UUID {
"bytes": Array [
Expand Down
10 changes: 10 additions & 0 deletions src/wallet-user/transaction-protection/LocCreation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ export default function LocCreation(props: Props) {
unit: Numbers.NONE,
value: "0",
},
collectionItemFee: {
unit: Numbers.NONE,
value: "0",
},
tokensRecordFee: {
unit: Numbers.NONE,
value: "0",
},
legalFee: undefined,
}
});
Expand Down Expand Up @@ -103,6 +111,8 @@ export default function LocCreation(props: Props) {
draft: true,
template: backendTemplate(selectedTemplateId),
valueFee: Currency.toCanonicalAmount(new Numbers.PrefixedNumber(formValues.valueFee.value, formValues.valueFee.unit)),
collectionItemFee: Currency.toCanonicalAmount(new Numbers.PrefixedNumber(formValues.collectionItemFee.value, formValues.collectionItemFee.unit)),
tokensRecordFee: Currency.toCanonicalAmount(new Numbers.PrefixedNumber(formValues.tokensRecordFee.value, formValues.tokensRecordFee.unit)),
legalFee: formValues.legalFee ? Currency.toCanonicalAmount(new Numbers.PrefixedNumber(formValues.legalFee.value, formValues.legalFee.unit)) : undefined,
}) as DraftRequest;
} else {
Expand Down
Loading

0 comments on commit f445ffe

Please sign in to comment.