Skip to content

Commit

Permalink
Merge pull request #316 from Chia-Network/tokenization-modal-fix
Browse files Browse the repository at this point in the history
Tokenization modal fix and workflow
  • Loading branch information
wwills2 authored Sep 3, 2024
2 parents 11b96bc + 193911c commit 6dc8302
Show file tree
Hide file tree
Showing 21 changed files with 155 additions and 79 deletions.
28 changes: 14 additions & 14 deletions .github/workflows/build-installers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
- name: Upload Mac Installer
uses: actions/upload-artifact@v3
with:
name: cadt-ui-mac-installer
name: tokenization-engine-ui-mac-installer
path: ${{ github.workspace }}/dist/*.dmg

build_windows:
Expand Down Expand Up @@ -117,7 +117,7 @@ jobs:
- name: Upload Windows Installer
uses: actions/upload-artifact@v3
with:
name: cadt-ui-windows-installer
name: tokenization-engine-ui-windows-installer
path: "${{ github.workspace }}/${{ env.INSTALLER_FILE }}"

build_linux:
Expand Down Expand Up @@ -152,7 +152,7 @@ jobs:
- name: Upload Linux Installer
uses: actions/upload-artifact@v3
with:
name: cadt-ui-linux-installer
name: tokenization-engine-ui-linux-installer
path: ${{ github.workspace }}/dist/*.deb

build_web:
Expand All @@ -177,13 +177,13 @@ jobs:
npm run build
- name: Create .tar.gz of the web build
run: tar -cvzf cadt-ui-web-build.tar.gz build
run: tar -cvzf tokenization-engine-ui-web-build.tar.gz build

- name: Upload build artifact
uses: actions/upload-artifact@v3
with:
name: cadt-ui-web-build
path: cadt-ui-web-build.tar.gz
name: tokenization-engine-ui-web-build
path: tokenization-engine-ui-web-build.tar.gz

release:
runs-on: ubuntu-latest
Expand All @@ -197,26 +197,26 @@ jobs:
- name: Download Windows artifacts
uses: actions/download-artifact@v3
with:
name: cadt-ui-windows-installer
path: cadt-ui-windows-installer
name: tokenization-engine-ui-windows-installer
path: tokenization-engine-ui-windows-installer

- name: Download MacOS artifacts
uses: actions/download-artifact@v3
with:
name: cadt-ui-mac-installer
path: cadt-ui-mac-installer
name: tokenization-engine-ui-mac-installer
path: tokenization-engine-ui-mac-installer

- name: Download Linux artifacts
uses: actions/download-artifact@v3
with:
name: cadt-ui-linux-installer
path: cadt-ui-linux-installer
name: tokenization-engine-ui-linux-installer
path: tokenization-engine-ui-linux-installer

- name: Download Web artifact
uses: actions/download-artifact@v3
with:
name: cadt-ui-web-build
path: cadt-ui-web-build
name: tokenization-engine-ui-web-build
path: tokenization-engine-ui-web-build

- name: Get Filenames
run: |
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ function App() {
useEffect(() => {
if (appStore.locale) {
const processTranslationTokens = async () => {
setTranslationTokens(await loadLocaleData(appStore.locale));
const tokens = loadLocaleData(appStore.locale);
setTranslationTokens(tokens);
};

processTranslationTokens();
Expand Down
8 changes: 4 additions & 4 deletions src/renderer/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './cadt/v1/projects.api';
export * from './cadt/v1/system.api';
export * from './cadt/v1/units.api';
export * from './cadt/v1/organizations.api';
export * from './tokenization-engine/projects.api';
export * from './tokenization-engine/system.api';
export * from './tokenization-engine/units.api';
export * from './tokenization-engine/organizations.api';
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ const baseQueryWithDynamicHost = async (args, api, extraOptions) => {
return await baseQuery(modifiedArgs, api, extraOptions);
};

export const cadtApi = createApi({
export const tokenizationEngineApi = createApi({
baseQuery: baseQueryWithDynamicHost,
reducerPath: 'cadtApi',
reducerPath: 'tokenizationEngineApi',
endpoints: () => ({}),
tagTypes: [projectsTag, untokenizedUnitsTag, tokenizedUnitsTag, projectsByIdsTag],
});
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { cadtApi } from './';
import { tokenizationEngineApi } from './index';
import { Organization } from '@/schemas/Organization.schema';
// @ts-ignore
import { BaseQueryResult } from '@reduxjs/toolkit/dist/query/baseQueryTypes';

const organizationsApi = cadtApi.injectEndpoints({
const organizationsApi = tokenizationEngineApi.injectEndpoints({
endpoints: (builder) => ({
getHomeOrg: builder.query<Organization | undefined, void | null>({
query: () => ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cadtApi, projectsByIdsTag, projectsTag, RECORDS_PER_PAGE } from './index';
import { projectsByIdsTag, projectsTag, RECORDS_PER_PAGE, tokenizationEngineApi } from './index';
import { Project } from '@/schemas/Project.schema';

interface GetProjectsParams {
Expand All @@ -22,7 +22,7 @@ interface GetProjectsResponse {
data: Project[];
}

const projectsApi = cadtApi.injectEndpoints({
const projectsApi = tokenizationEngineApi.injectEndpoints({
endpoints: (builder) => ({
getProjects: builder.query<GetProjectsResponse, GetProjectsParams>({
query: ({ page, orgUid, search, order }: GetProjectsParams) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cadtApi } from './index';
import { tokenizationEngineApi } from './index';
// @ts-ignore
import { BaseQueryResult } from '@reduxjs/toolkit/dist/query/baseQueryTypes';
import _ from 'lodash';
Expand All @@ -22,7 +22,7 @@ export interface Config {
apiHost?: string;
}

const systemApi = cadtApi.injectEndpoints({
const systemApi = tokenizationEngineApi.injectEndpoints({
endpoints: (builder) => ({
getHealth: builder.query<ServerHealth, GetHealthParams>({
query: ({ apiHost = '', apiKey }) => ({
Expand All @@ -35,6 +35,7 @@ const systemApi = cadtApi.injectEndpoints({
const readOnly = meta?.response?.headers.get('cw-readonly') === 'true';
return { isHealthy, readOnly };
},
keepUnusedDataFor: 0,
}),
getHealthImmediate: builder.mutation<boolean, GetHealthParams>({
query: ({ apiHost = '', apiKey }) => ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
cadtApi,
projectsByIdsTag,
projectsTag,
RECORDS_PER_PAGE,
tokenizationEngineApi,
tokenizedUnitsTag,
untokenizedUnitsTag,
} from './index';
Expand All @@ -28,7 +28,7 @@ export interface GetUnitsResponse {
data: Unit[];
}

const unitsApi = cadtApi.injectEndpoints({
const unitsApi = tokenizationEngineApi.injectEndpoints({
endpoints: (builder) => ({
getUntokenizedUnits: builder.query<GetUnitsResponse, GetUnitsParams>({
query: ({ page, search, order, filter }: GetUnitsParams) => {
Expand Down
9 changes: 9 additions & 0 deletions src/renderer/components/blocks/forms/CreateTokenForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ import * as yup from 'yup';
import { FloatingLabel, FormButton, HelperText, Spacer } from '@/components';
import { FormattedMessage, IntlShape, useIntl } from 'react-intl';

export interface TokenData {
org_uid: string;
warehouse_project_id: string;
vintage_year: number;
sequence_num: number;
warehouseUnitId: string;
amount: number;
}

interface FormProps {
onSubmit: (walletAddress: string) => Promise<void>;
onClearError?: () => void;
Expand Down
3 changes: 1 addition & 2 deletions src/renderer/components/blocks/layout/LeftNav.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { useCallback } from 'react';
import { useLocation, useNavigate } from 'react-router-dom';
import { FormattedMessage } from 'react-intl';
import { Card, Sidebar } from '@/components';
import { Card, NoHomeOrgModal, Sidebar } from '@/components';
import ROUTES from '@/routes/route-constants';
import { RiTokenSwapLine } from 'react-icons/ri';
import { NoHomeOrgModal } from '@/components/blocks/modals/NoHomeOrgModal';

const LeftNav = () => {
const navigate = useNavigate();
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/blocks/layout/PageCounter.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { RECORDS_PER_PAGE } from '@/api/cadt/v1';
import { RECORDS_PER_PAGE } from '@/api/tokenization-engine';

// Define an interface for the component's props
interface PageCounterProps {
Expand Down
40 changes: 23 additions & 17 deletions src/renderer/components/blocks/modals/CreateTokenModal.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
import React, { useEffect, useState } from 'react';
import React, { useState } from 'react';
import { ComponentCenteredSpinner, CreateTokenForm, Modal, Table } from '@/components';
import { FormattedMessage } from 'react-intl';
import { useGetProjectQuery, useGetUnitQuery, useTokenizeUnitMutation } from '@/api';
import { Alert } from 'flowbite-react';
import { HiInformationCircle } from 'react-icons/hi';
import { useWildCardUrlHash } from '@/hooks';

interface UpsertModalProps {
tokenizeUrlFragment: string;
onTokenizationSuccess: () => void;
onClose: () => void;
}

const CreateTokenModal: React.FC<UpsertModalProps> = ({ onClose, tokenizeUrlFragment }: UpsertModalProps) => {
const CreateTokenModal: React.FC<UpsertModalProps> = ({ onClose, onTokenizationSuccess }: UpsertModalProps) => {
const [tokenizeUrlFragment] = useWildCardUrlHash('tokenize');
const urlHashValues: string[] = tokenizeUrlFragment?.replace('tokenize-', '')?.split('^');
const warehouseUnitId = urlHashValues?.length >= 1 ? urlHashValues[0] : '';
const warehouseProjectId = urlHashValues?.length >= 2 ? urlHashValues[1] : '';
const { data: unit, isFetching: unitLoading } = useGetUnitQuery({ warehouseUnitId });
const { data: project, isFetching: projectLoading } = useGetProjectQuery({ warehouseProjectId });
const [triggerTokenizeUnit, { isLoading: tokenizationLoading, error: tokenizationError }] = useTokenizeUnitMutation();
const [showTokenizationFailure, setShowTokenizationFailure] = useState<boolean>(false);

useEffect(() => {
if (tokenizationError) {
setShowTokenizationFailure(true);
} else if (tokenizationLoading) {
setShowTokenizationFailure(false);
}
}, [tokenizationError, tokenizationLoading]);
const [showTokenizationFailure, setShowTokenizationFailure] = useState<boolean>(false);
const { data: unit, isLoading: unitLoading } = useGetUnitQuery(
{ warehouseUnitId },
{ skip: showTokenizationFailure },
);
const { data: project, isLoading: projectLoading } = useGetProjectQuery(
{ warehouseProjectId },
{ skip: showTokenizationFailure },
);
const [triggerTokenizeUnit, { error: tokenizationError }] = useTokenizeUnitMutation();

const requiredFieldsPresent =
unit &&
Expand All @@ -38,7 +39,9 @@ const CreateTokenModal: React.FC<UpsertModalProps> = ({ onClose, tokenizeUrlFrag
unit?.unitBlockEnd &&
unit?.unitCount;

const onSumbitTokenization = async (walletAddress: string) => {
const onSubmitTokenization = async (walletAddress: string) => {
setShowTokenizationFailure(false);

if (unit && project) {
const submitData = {
org_uid: unit?.orgUid,
Expand All @@ -51,8 +54,11 @@ const CreateTokenModal: React.FC<UpsertModalProps> = ({ onClose, tokenizeUrlFrag
};

const result = await triggerTokenizeUnit(submitData);
if (result?.error) {
if (result?.error || tokenizationError) {
setShowTokenizationFailure(true);
} else {
onClose();
onTokenizationSuccess();
}
}
};
Expand Down Expand Up @@ -162,7 +168,7 @@ const CreateTokenModal: React.FC<UpsertModalProps> = ({ onClose, tokenizeUrlFrag
</Table>
</div>
<div>
<CreateTokenForm onSubmit={onSumbitTokenization} />
<CreateTokenForm onSubmit={onSubmitTokenization} />
</div>
</div>
);
Expand Down
32 changes: 32 additions & 0 deletions src/renderer/components/blocks/modals/TokenizationSuccessModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Modal } from '@/components';
import { FormattedMessage } from 'react-intl';
import React from 'react';

const TokenizationSuccessModal: React.FC<{ onClose: () => void }> = ({ onClose }) => {
return (
<Modal show={true} onClose={onClose}>
<Modal.Header>
<p className="capitalize">
<FormattedMessage id="unit-tokenization-success" />
</p>
</Modal.Header>
<Modal.Body>
<div className="space-y-2.5">
<p className="sentence-case">
<FormattedMessage id="the-unit-has-been-successfully-submitted-for-tokenization-and-is-pending-confirmation-on-the-blockchain" />
.
</p>
<p className="sentence-case">
<FormattedMessage id="this-process-will-take-a-few-minutes" />.
</p>
<p className="sentence-case">
<FormattedMessage id="please-check-your-wallet-for-transactions-and-refresh-this-page-when-a-new-transaction-is-confirmed" />
.
</p>
</div>
</Modal.Body>
</Modal>
);
};

export { TokenizationSuccessModal };
2 changes: 2 additions & 0 deletions src/renderer/components/blocks/modals/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export * from './ConnectModal';
export * from './CreateTokenModal';
export * from './TokenizationSuccessModal';
export * from './NoHomeOrgModal';
Loading

0 comments on commit 6dc8302

Please sign in to comment.