Skip to content

Commit

Permalink
feat: close, transfer, publish, import.
Browse files Browse the repository at this point in the history
  • Loading branch information
gdethier committed Nov 24, 2023
1 parent 70855e4 commit 9a8e23d
Show file tree
Hide file tree
Showing 12 changed files with 408 additions and 218 deletions.
5 changes: 3 additions & 2 deletions src/ExtrinsicSubmissionStateView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import ExtrinsicSubmissionResult from './ExtrinsicSubmissionResult';
export interface Props {
successMessage?: string;
slim?: boolean;
submissionId?: string;
}

export default function ExtrinsicSubmissionStateView(props: Props) {
const { extrinsicSubmissionState } = useLogionChain();

if(extrinsicSubmissionState.submitted) {
return (<ExtrinsicSubmissionResult
error={ extrinsicSubmissionState.error }
result={ extrinsicSubmissionState.result }
error={ extrinsicSubmissionState.getError(props.submissionId) }
result={ extrinsicSubmissionState.getResult(props.submissionId) }
successMessage={ props.successMessage }
slim={ props.slim }
/>);
Expand Down
8 changes: 5 additions & 3 deletions src/common/WalletGauge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ export default function WalletGauge(props: Props) {
};
}, [ amount, destination, unit, mutateBalanceState, signer, expectNewTransaction ]);

const transferCallback = useCallback(() => {
submitCall(transfer);
const transferCallback = useCallback(async () => {
try {
await submitCall(transfer);
} catch(e) {}
}, [ transfer, submitCall ]);

const clearFormCallback = useCallback(() => {
Expand Down Expand Up @@ -131,7 +133,7 @@ export default function WalletGauge(props: Props) {
buttonText: "Cancel",
buttonVariant: 'secondary-polkadot',
callback: cancelCallback,
disabled: extrinsicSubmissionState.submitted && !extrinsicSubmissionState.callEnded,
disabled: extrinsicSubmissionState.inProgress,
},
{
id: 'transfer',
Expand Down
9 changes: 5 additions & 4 deletions src/loc/CloseLocButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ enum CloseStatus {
NONE,
ACCEPT,
CLOSE_PENDING,
CLOSING,
DONE
CLOSING
}

interface CloseState {
Expand Down Expand Up @@ -60,9 +59,11 @@ export default function CloseLocButton(props: Props) {
});
}, [ mutateLocState, autoAck, signer ]);

const close = useCallback(() => {
const close = useCallback(async () => {
setCloseState({ status: CloseStatus.CLOSING });
submitCall(closeCall);
try {
await submitCall(closeCall);
} catch(e) {}
}, [ closeCall, submitCall ]);

const clear = useCallback(() => {
Expand Down
7 changes: 1 addition & 6 deletions src/loc/ImportItems.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ import { setLocState, refresh } from "./__mocks__/UserLocContextMock";
import { CollectionItem, Fees, UUID } from "@logion/node-api";
import { H256 } from "@logion/node-api/dist/types/interfaces";
import { LogionClient, AddCollectionItemParams, EstimateFeesAddCollectionItemParams } from "@logion/client";
import { mockSubmittableResult } from "../logion-chain/__mocks__/SignatureMock";
import { SUCCESSFUL_SUBMISSION, setClientMock, setExtrinsicSubmissionState } from 'src/logion-chain/__mocks__/LogionChainMock';
import { It, Mock } from 'moq.ts';
import { SubmittableExtrinsic } from '@polkadot/api/promise/types';
import { Compact, u128 } from "@polkadot/types-codec";
import { TEST_WALLET_USER } from 'src/wallet-user/TestData';

jest.mock("../common/CommonContext");
jest.mock("../logion-chain/Signature");
jest.mock("../logion-chain");
jest.mock("./UserLocContext");

Expand All @@ -29,9 +27,7 @@ describe("ImportItems", () => {
await userEvent.click(importAllButton);
await waitFor(() => expect(screen.getByRole("button", { name: "Proceed" })).toBeVisible());
await clickByName("Proceed");
await waitFor(() => expect(screen.getByRole("button", { name: "Proceed" })).toBeVisible());
await clickByName("Proceed");
await waitFor(() => expect(collection.addCollectionItem).toBeCalled());
await waitFor(() => expect(collection.addCollectionItem).toBeCalledTimes(2));

await waitFor(() => expect(screen.getAllByRole("img", {name: "ok"}).length).toBe(2));

Expand Down Expand Up @@ -69,7 +65,6 @@ async function uploadCsv(): Promise<any> {

const collection = {
addCollectionItem: jest.fn((params: AddCollectionItemParams) => {
params.callback!(mockSubmittableResult(true, "finalized"));
return Promise.resolve();
}),
estimateFeesAddCollectionItem: jest.fn((params: EstimateFeesAddCollectionItemParams) => {
Expand Down
Loading

0 comments on commit 9a8e23d

Please sign in to comment.