Skip to content
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
2 changes: 2 additions & 0 deletions src/context/AssetContext/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
SecurityIdentifier,
TickerReservation,
TickerReservationDetails,
TransferRestrictionExemption,
TransferRestrictionStatValues,
Venue,
} from '@polymeshassociation/polymesh-sdk/types';
Expand Down Expand Up @@ -56,6 +57,7 @@ export interface IDetails {
compliancePaused: boolean;
transferRestrictions?: ActiveTransferRestrictions;
trackedStatistics?: TransferRestrictionStatValues[];
exemptions?: TransferRestrictionExemption[];
}
export interface IAssetDetails {
assetId: string;
Expand Down
6 changes: 6 additions & 0 deletions src/context/AssetContext/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ const AssetProvider = ({ children }: IProviderProps) => {
compliancePaused,
transferRestrictions,
trackedStatistics,
exemptions,
] = await Promise.all([
asset.details(),
asset instanceof NftCollection ? asset.getCollectionId() : undefined,
Expand All @@ -127,6 +128,10 @@ const AssetProvider = ({ children }: IProviderProps) => {
asset instanceof FungibleAsset
? asset.transferRestrictions.getValues()
: undefined,

asset instanceof FungibleAsset
? asset.transferRestrictions.getExemptions()
: undefined,
]);

// Fetch all metadata entries with their details and values (if set)
Expand Down Expand Up @@ -186,6 +191,7 @@ const AssetProvider = ({ children }: IProviderProps) => {
compliancePaused,
transferRestrictions,
trackedStatistics,
exemptions,
},
docs: docs.data,
};
Expand Down
106 changes: 106 additions & 0 deletions src/hooks/polymesh/useAssetActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import type {
InputCondition,
NftMetadataInput,
Requirement,
TransferRestrictionClaimCountInput,
TransferRestrictionExemptionParams,
TransferRestrictionInputClaimPercentage,
TransferRestrictionInputCount,
TransferRestrictionInputPercentage,
TrustedFor,
} from '@polymeshassociation/polymesh-sdk/types';
import {
Expand Down Expand Up @@ -1057,6 +1062,104 @@ const useAssetActions = (
}
};

const setTransferRestrictions = async ({
restrictions,
onTransactionRunning,
}: {
restrictions: (
| TransferRestrictionInputCount
| TransferRestrictionInputPercentage
| TransferRestrictionClaimCountInput
| TransferRestrictionInputClaimPercentage
)[];
onTransactionRunning?: () => void | Promise<void>;
}) => {
if (!asset) {
notifyError('Asset not available');
return;
}

// Type narrow: only FungibleAsset supports transfer restrictions
if (!('issuance' in asset)) {
notifyError(
'Transfer restrictions are only supported for fungible assets, not NFT collections',
);
return;
}

try {
await executeTransaction(
asset.transferRestrictions.setRestrictions({ restrictions }),
createOptions(onTransactionRunning),
);
} catch (error) {
// Error is already handled by the transaction context and notified to the user
// This catch block prevents unhandled promise rejection
}
};

const addExemptions = async ({
exemptions,
onTransactionRunning,
}: {
exemptions: TransferRestrictionExemptionParams;
onTransactionRunning?: () => void | Promise<void>;
}) => {
if (!asset) {
notifyError('Asset not available');
return;
}

// Type narrow: only FungibleAsset supports transfer restrictions
if (!('issuance' in asset)) {
notifyError(
'Transfer restrictions are only supported for fungible assets, not NFT collections',
);
return;
}

try {
await executeTransaction(
asset.transferRestrictions.addExemptions(exemptions),
createOptions(onTransactionRunning),
);
} catch (error) {
// Error is already handled by the transaction context and notified to the user
// This catch block prevents unhandled promise rejection
}
};

const removeExemptions = async ({
exemptions,
onTransactionRunning,
}: {
exemptions: TransferRestrictionExemptionParams;
onTransactionRunning?: () => void | Promise<void>;
}) => {
if (!asset) {
notifyError('Asset not available');
return;
}

// Type narrow: only FungibleAsset supports transfer restrictions
if (!('issuance' in asset)) {
notifyError(
'Transfer restrictions are only supported for fungible assets, not NFT collections',
);
return;
}

try {
await executeTransaction(
asset.transferRestrictions.removeExemptions(exemptions),
createOptions(onTransactionRunning),
);
} catch (error) {
// Error is already handled by the transaction context and notified to the user
// This catch block prevents unhandled promise rejection
}
};

return {
issueTokens,
redeemTokens,
Expand Down Expand Up @@ -1097,6 +1200,9 @@ const useAssetActions = (
modifyComplianceRule,
removeComplianceRule,
setTransferRestrictionStats,
setTransferRestrictions,
addExemptions,
removeExemptions,
transactionInProcess,
};
};
Expand Down
Loading