Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable auto-publish #522

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/loc/OpenLoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,18 @@
font-size: 1.2rem;
padding-top: 7px;
}

.OpenLoc .toggle-button-container {
display: flex;
}

.OpenLoc .toggle-container {
display: flex;
padding-right: 20px;
padding-top: 7px;
}

.OpenLoc .toggle-container p {
padding-right: 20px;
margin: 0;
}
49 changes: 37 additions & 12 deletions src/loc/OpenLoc.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState, useEffect, useCallback } from 'react';
import { useState, useEffect, useCallback, useMemo } from 'react';
import { Fees } from '@logion/node-api';
import { LocData } from '@logion/client';
import { useLogionChain } from '../logion-chain';
Expand All @@ -14,6 +14,7 @@ import { AcceptedRequest } from "@logion/client/dist/Loc";
import Button from 'src/common/Button';
import PolkadotFrame from 'src/common/PolkadotFrame';
import "./OpenLoc.css";
import Checkbox from 'src/components/toggle/Checkbox';

enum OpenStatus {
NONE,
Expand All @@ -36,6 +37,7 @@ export default function OpenLoc(props: Props) {
const [ error, setError ] = useState<boolean>(false);
const [ limits, setLimits ] = useState<CollectionLimits>(DEFAULT_LIMITS);
const [ fees, setFees ] = useState<Fees | undefined | null>();
const [ autoPublish, setAutoPublish ] = useState(false);

useEffect(() => {
if(fees === undefined && client) {
Expand All @@ -44,14 +46,17 @@ export default function OpenLoc(props: Props) {
if (locState instanceof AcceptedRequest) {
if (locState.data().locType === "Collection") {
const apiLimits = await limits.toApiLimits(client.logionApi)
setFees(await locState.estimateFeesOpenCollection(apiLimits));
setFees(await locState.estimateFeesOpenCollection({
...apiLimits,
autoPublish,
}));
} else {
setFees(await locState.estimateFeesOpen());
setFees(await locState.estimateFeesOpen(autoPublish));
}
}
})();
}
}, [ fees, client, props.loc, limits, locState ]);
}, [ fees, client, props.loc, limits, locState, autoPublish ]);

// LOC creation
useEffect(() => {
Expand All @@ -64,13 +69,15 @@ export default function OpenLoc(props: Props) {
return current.open({
signer,
callback,
autoPublish
});
} else {
const apiLimits = await limits.toApiLimits(client.logionApi)
return current.openCollection({
...apiLimits,
signer,
callback,
autoPublish
});
}
} else {
Expand All @@ -85,6 +92,7 @@ export default function OpenLoc(props: Props) {
signer,
limits,
client,
autoPublish,
]);

const resetFields = useCallback(() => {
Expand All @@ -101,6 +109,12 @@ export default function OpenLoc(props: Props) {
refresh(false);
}, [ refresh, close ]);

const canAutoPublish = useMemo(() => {
return locState?.data().metadata.find(item => item.status === "REVIEW_ACCEPTED") !== undefined
&& locState?.data().files.find(item => item.status === "REVIEW_ACCEPTED") !== undefined
&& locState?.data().links.find(item => item.status === "REVIEW_ACCEPTED") !== undefined;
}, [ locState ]);

let title;
if(props.loc.locType === 'Transaction') {
title = "Transaction Legal Officer Case (LOC) creation";
Expand All @@ -120,14 +134,25 @@ export default function OpenLoc(props: Props) {
<div className="text-container">
Do you want to create this LOC?
</div>
<div className="button-container">
<Button
onClick={ () => setAcceptState(OpenStatus.CREATE_LOC) }
data-testid={ `accept-${ props.loc.id }` }
variant="polkadot"
>
Create LOC
</Button>
<div className="toggle-button-container">
<div className="toggle-container">
<p>Publish accepted?</p>
<Checkbox
skin="Toggle white"
checked={ autoPublish }
setChecked={ (value) => setAutoPublish(value) }
disabled={ !canAutoPublish }
/>
</div>
<div className="button-container">
<Button
onClick={ () => setAcceptState(OpenStatus.CREATE_LOC) }
data-testid={ `accept-${ props.loc.id }` }
variant="polkadot"
>
Create LOC
</Button>
</div>
</div>
</div>
<ProcessStep
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2977,14 +2977,14 @@ __metadata:
linkType: hard

"@logion/client@npm:^0.33.0-1, @logion/client@npm:^0.33.0-2":
version: 0.33.0-5
resolution: "@logion/client@npm:0.33.0-5"
version: 0.33.0-10
resolution: "@logion/client@npm:0.33.0-10"
dependencies:
"@logion/node-api": ^0.24.0-1
"@logion/node-api": ^0.24.0-2
axios: ^0.27.2
luxon: ^3.0.1
mime-db: ^1.52.0
checksum: 482cd72c69da03ac667bcad1dce6165d28ad83eb3b47f2c32d445f778581b85ad67b3fc6f5b33fbe7cd8c0107e5828c4f3e4a1323aff33467c0d1931966088df
checksum: b25e8c6ae8df99e593b09ea8a62b4fc42e3ba4bfc38b86eeae71710919d0f352feefd37ddfb215a5f9bd51940cf0496a242dd2d33d974b1639fba4b2d7d76bb9
languageName: node
linkType: hard

Expand Down Expand Up @@ -3020,7 +3020,7 @@ __metadata:
languageName: node
linkType: hard

"@logion/node-api@npm:^0.24.0-1":
"@logion/node-api@npm:^0.24.0-2":
version: 0.24.0-2
resolution: "@logion/node-api@npm:0.24.0-2"
dependencies:
Expand Down