Skip to content

Commit

Permalink
chore(rwa): check on the max investors compliance (#2772)
Browse files Browse the repository at this point in the history
  • Loading branch information
sstraatemans authored Jan 7, 2025
1 parent 7ac01e1 commit 839d61f
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .changeset/lovely-pots-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ export const FormatDeleteInvestor = () => {
investorAccount,
});

console.log(notAllowedReason);

const handleDelete = async () => {
await submit({ investor: investorAccount });
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ const interpretMessage = (str: string, data?: ITransaction): string => {
if (str?.includes('buy gas failed')) {
return `This account does not have enough balance to pay for Gas`;
}
if (str?.includes('exceeds max investor')) {
return `The maximum amount of investors has been reached`;
}

return `${data?.type}: ${str}`;
};
Expand Down Expand Up @@ -124,11 +127,20 @@ export const TransactionsProvider: FC<PropsWithChildren> = ({ children }) => {

r.subscribe(
(nextData: any) => {
if (nextData?.errors?.length !== undefined) {
if (
nextData?.errors?.length !== undefined ||
nextData?.data?.transaction?.result.badResult
) {
addNotification({
intent: 'negative',
label: 'there was an error',
message: JSON.stringify(nextData?.errors),
message: interpretErrorMessage(
nextData?.errors
? JSON.stringify(nextData?.errors)
: JSON.parse(
nextData?.data.transaction?.result.badResult ?? '{}',
).message,
),
url: `https://explorer.kadena.io/${activeNetwork.networkId}/transaction/${data.requestKey}`,
});
return;
Expand Down
9 changes: 7 additions & 2 deletions packages/apps/rwa-demo/src/hooks/distributeTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
interpretErrorMessage,
TXTYPES,
} from '@/components/TransactionsProvider/TransactionsProvider';
import { INFINITE_COMPLIANCE } from '@/constants';
import type { IDistributeTokensProps } from '@/services/distributeTokens';
import { distributeTokens } from '@/services/distributeTokens';
import { getClient } from '@/utils/client';
Expand Down Expand Up @@ -56,8 +57,12 @@ export const useDistributeTokens = ({
!paused &&
accountRoles.isSupplyModifier() &&
!isActiveAccountChangeTx &&
((asset.maxSupply >= 0 && asset.supply < asset.maxSupply) ||
asset.maxSupply < 0),
((asset.maxSupply > INFINITE_COMPLIANCE &&
asset.supply < asset.maxSupply) ||
asset.maxSupply === INFINITE_COMPLIANCE) &&
((asset.maxInvestors > INFINITE_COMPLIANCE &&
asset.maxInvestors > asset.investorCount) ||
asset.maxInvestors === INFINITE_COMPLIANCE),
);
}, [
frozen,
Expand Down
2 changes: 1 addition & 1 deletion packages/apps/rwa-demo/src/services/pact/modelcontract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1369,5 +1369,5 @@ export const getContract = ({ contractName, namespace }: IAddContractProps) => `
(RWA.token-mapper.add-token-ref TOKEN-ID ${namespace}.${contractName})
(${namespace}.${contractName}.init "${contractName}" "MVP" 0 "kadenaID" "0.0" [RWA.max-balance-compliance RWA.supply-limit-compliance] false (keyset-ref-guard "${namespace}.admin-keyset"))
(${namespace}.${contractName}.init "${contractName}" "MVP" 0 "kadenaID" "0.0" [RWA.max-balance-compliance RWA.supply-limit-compliance RWA.max-investors-compliance] false (keyset-ref-guard "${namespace}.admin-keyset"))
`;

0 comments on commit 839d61f

Please sign in to comment.