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

fix(rwa): fix small bugs #2764

Merged
merged 1 commit into from
Dec 23, 2024
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
6 changes: 3 additions & 3 deletions packages/apps/rwa-demo/src/app/(app)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@ const Home = () => {
{asset && (
<>
<ComplianceRule
value={asset.maxSupply}
value={`${asset.maxSupply < 0 ? 0 : asset.maxSupply} tokens`}
label="Supply limit"
/>
<ComplianceRule
value={asset.maxBalance}
value={`${asset.maxBalance < 0 ? 0 : asset.maxBalance} tokens`}
label="Max balance"
/>
<ComplianceRule
value={`${asset.maxInvestors} (${asset.investorCount})`}
value={`${asset.maxInvestors < 0 ? 0 : asset.maxInvestors} (${asset.investorCount}) investors`}
label="Max Investors"
/>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { cloneElement, useEffect, useRef, useState } from 'react';
import { Controller, useForm } from 'react-hook-form';
import { AssetPausedMessage } from '../AssetPausedMessage/AssetPausedMessage';
import { InvestorFrozenMessage } from '../InvestorFrozenMessage/InvestorFrozenMessage';
import { NoComplianceMessage } from '../NoComplianceMessage/NoComplianceMessage';
import { SendTransactionAnimation } from '../SendTransactionAnimation/SendTransactionAnimation';
import type { ITransaction } from '../TransactionsProvider/TransactionsProvider';

Expand Down Expand Up @@ -106,7 +107,7 @@ export const DistributionForm: FC<IProps> = ({
label="Amount"
{...field}
errorMessage={errors.amount?.message}
description={`max amount: ${maxAmount} `}
description={`max amount: ${maxAmount < 0 ? 0 : maxAmount} `}
/>
)}
/>
Expand All @@ -116,6 +117,7 @@ export const DistributionForm: FC<IProps> = ({
<>
<InvestorFrozenMessage investorAccount={investorAccount} />
<AssetPausedMessage />
<NoComplianceMessage />
</>
}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const InvestorBalance: FC<IProps> = ({
});
const { data: frozenData } = useGetFrozenTokens({ investorAccount });

const cleanedBalance = balance < 0 ? 0 : balance;
if (short) {
return (
<Stack alignItems="center" gap="xs">
Expand All @@ -33,15 +34,15 @@ export const InvestorBalance: FC<IProps> = ({
]}
account={investorAccount}
/>
<MaxInvestorBalanceCheck balance={balance} />
{balance} (<MonoFilterTiltShift /> {frozenData})
<MaxInvestorBalanceCheck balance={cleanedBalance} />
{cleanedBalance} (<MonoFilterTiltShift /> {frozenData})
</Stack>
);
}

return (
<Stack alignItems="center" gap="xs">
<MaxInvestorBalanceCheck balance={balance} />
<MaxInvestorBalanceCheck balance={cleanedBalance} />
investorBalance:{' '}
<TransactionTypeSpinner
type={[
Expand All @@ -51,7 +52,7 @@ export const InvestorBalance: FC<IProps> = ({
]}
account={investorAccount}
/>
{balance} (<MonoFilterTiltShift /> {frozenData})
{cleanedBalance} (<MonoFilterTiltShift /> {frozenData})
</Stack>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { useAsset } from '@/hooks/asset';
import { Notification } from '@kadena/kode-ui';
import type { FC } from 'react';

export const NoComplianceMessage: FC = () => {
const { asset } = useAsset();

if (
(asset?.maxSupply ?? -1) >= 0 &&
(asset?.maxBalance ?? -1) >= 0 &&
(asset?.maxInvestors ?? -1) >= 0
)
return;
return (
<Notification intent="info" role="status">
There are no compliance rules set
</Notification>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ export const SetComplianceForm: FC<IProps> = ({ onClose, trigger }) => {
const { asset } = useAsset();
const { setIsRightAsideExpanded, isRightAsideExpanded } = useLayout();
const [isOpen, setIsOpen] = useState(false);
const { handleSubmit, reset, control } = useForm<ISetComplianceProps>({
const {
handleSubmit,
reset,
control,
formState: { isValid },
} = useForm<ISetComplianceProps>({
defaultValues: {
maxBalance: `${asset?.maxBalance ?? 0}`,
maxSupply: `${asset?.maxSupply ?? 0}`,
Expand Down Expand Up @@ -67,7 +72,7 @@ export const SetComplianceForm: FC<IProps> = ({ onClose, trigger }) => {
<Controller
name="maxBalance"
control={control}
rules={{ required: true }}
rules={{ required: true, min: 0 }}
render={({ field }) => (
<TextField type="number" label="Max Balance" {...field} />
)}
Expand All @@ -76,15 +81,15 @@ export const SetComplianceForm: FC<IProps> = ({ onClose, trigger }) => {
<Controller
name="maxSupply"
control={control}
rules={{ required: true }}
rules={{ required: true, min: 0 }}
render={({ field }) => (
<TextField type="number" label="Max Supply" {...field} />
)}
/>
<Controller
name="maxInvestors"
control={control}
rules={{ required: true }}
rules={{ required: true, min: 0 }}
render={({ field }) => (
<TextField
type="number"
Expand All @@ -98,7 +103,7 @@ export const SetComplianceForm: FC<IProps> = ({ onClose, trigger }) => {
<Button onPress={onClose} variant="transparent">
Cancel
</Button>
<Button isDisabled={!isAllowed} type="submit">
<Button isDisabled={!isAllowed || !isValid} type="submit">
Set Compliance
</Button>
</RightAsideFooter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export const TransactionsProvider: FC<PropsWithChildren> = ({ children }) => {
},
);

return true;
return 2222;
},
[],
);
Expand Down
2 changes: 2 additions & 0 deletions packages/apps/rwa-demo/src/hooks/getAgents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ export const useGetAgents = () => {
variables: {
qualifiedName: `${getAsset()}.AGENT-ADDED`,
},
fetchPolicy: 'no-cache',
});

const { data: removedData, loading: removedLoading } = useEventsQuery({
variables: {
qualifiedName: `${getAsset()}.AGENT-REMOVED`,
},
fetchPolicy: 'no-cache',
});

const { data: subscriptionAddData } = useEventSubscriptionSubscription({
Expand Down
2 changes: 2 additions & 0 deletions packages/apps/rwa-demo/src/hooks/getInvestors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ export const useGetInvestors = () => {
variables: {
qualifiedName: `${getAsset()}.IDENTITY-REGISTERED`,
},
fetchPolicy: 'no-cache',
});

const { data: removedData, loading: removedLoading } = useEventsQuery({
variables: {
qualifiedName: `${getAsset()}.IDENTITY-REMOVED`,
},
fetchPolicy: 'no-cache',
});

const { data: addedSubscriptionData } = useEventSubscriptionSubscription({
Expand Down
5 changes: 4 additions & 1 deletion packages/apps/rwa-demo/src/utils/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ const RWAStore = () => {
const addTransaction = async (data: ITransaction) => {
const asset = getAssetFolder();

await set(ref(database, `${asset}/transactions/${data.uuid}`), data);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { listener, ...newData } = data;

await set(ref(database, `${asset}/transactions/${data.uuid}`), newData);
};

const removeTransaction = async (data: ITransaction) => {
Expand Down
Loading