Skip to content

Commit 9eb5abe

Browse files
committed
feat: filter transfer share destinations using allowTransferShares flag
Extract shared helper and use allowTransferShares from smart_contracts.json to control destination contract eligibility in transfer rights form.
1 parent 222d245 commit 9eb5abe

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

src/app/assets/assets.component.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { shortenAddress } from '../utils/address.utils';
2323
import { ExplorerUrlHelper } from '../services/explorer-url.helper';
2424
import { QubicStaticService } from '../services/apis/static/qubic-static.service';
2525
import { StaticSmartContract } from '../services/apis/static/qubic-static.model';
26-
import { ASSET_TRANSFER_FEE, TRANSFER_SHARE_MANAGEMENT_RIGHTS_PROCEDURE } from '../constants/qubic.constants';
26+
import { ASSET_TRANSFER_FEE, supportsTransferShareRights } from '../constants/qubic.constants';
2727

2828
// Interfaces for asset grouping
2929
interface GroupedAsset {
@@ -686,13 +686,8 @@ export class AssetsComponent implements OnInit, OnDestroy {
686686
const contract = this.smartContractsMap.get(mc.contractIndex);
687687
if (!contract) return false;
688688

689-
// Dynamically check if contract has the transfer rights procedure
690-
const hasProcedure = contract.procedures.some(
691-
p => p.name === TRANSFER_SHARE_MANAGEMENT_RIGHTS_PROCEDURE
692-
);
693-
694-
// Must have procedure and positive balance
695-
return hasProcedure && mc.asset.ownedAmount > 0;
689+
// Must support transfer rights and have positive balance
690+
return supportsTransferShareRights(contract) && mc.asset.ownedAmount > 0;
696691
});
697692
}
698693

src/app/assets/transfer-rights/transfer-rights.component.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { PublicKey } from '@qubic-lib/qubic-ts-library/dist/qubic-types/PublicKe
2525
import { DynamicPayload } from '@qubic-lib/qubic-ts-library/dist/qubic-types/DynamicPayload';
2626

2727
import { shortenAddress } from '../../utils/address.utils';
28-
import { TRANSFER_SHARE_MANAGEMENT_RIGHTS_PROCEDURE } from '../../constants/qubic.constants';
28+
import { TRANSFER_SHARE_MANAGEMENT_RIGHTS_PROCEDURE, supportsTransferShareRights } from '../../constants/qubic.constants';
2929

3030
/**
3131
* Interface for contracts that can manage assets
@@ -373,8 +373,10 @@ export class TransferRightsComponent implements OnInit, OnDestroy {
373373
private buildDestinationContractOptions(): void {
374374
const contracts: ManagingContractOption[] = [];
375375

376-
// Dynamically find ALL contracts that support the transfer rights procedure
376+
// Find contracts that support transfer share rights
377377
for (const [contractIndex, contract] of this.smartContractsMap.entries()) {
378+
if (!supportsTransferShareRights(contract)) continue;
379+
378380
const procedure = this.findTransferRightsProcedure(contract);
379381

380382
if (procedure) {

src/app/constants/qubic.constants.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,12 @@ export const ASSET_TRANSFER_FEE = QubicDefinitions.QX_TRANSFER_ASSET_FEE;
2828
* Used to dynamically find this procedure in smart contracts JSON
2929
*/
3030
export const TRANSFER_SHARE_MANAGEMENT_RIGHTS_PROCEDURE = 'Transfer Share Management Rights';
31+
32+
/**
33+
* Check if a smart contract supports transfer share management rights.
34+
* Requires both the allowTransferShares flag and the procedure to be present.
35+
*/
36+
export function supportsTransferShareRights(contract: { allowTransferShares?: boolean; procedures: { name: string }[] }): boolean {
37+
return !!contract.allowTransferShares &&
38+
contract.procedures.some(p => p.name.toLowerCase() === TRANSFER_SHARE_MANAGEMENT_RIGHTS_PROCEDURE.toLowerCase());
39+
}

src/app/services/apis/static/qubic-static.model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export interface StaticSmartContract {
1818
address: string;
1919
procedures: SmartContractProcedure[];
2020
website?: string;
21+
allowTransferShares?: boolean;
2122
}
2223

2324
export interface GetSmartContractsResponse {

0 commit comments

Comments
 (0)