Skip to content

Commit 4e0d6e1

Browse files
committed
feat: filter transfer share destinations using allowTransferShares flag
Use allowTransferShares from smart_contracts.json to control which contracts can be selected as destination in the transfer management rights form. Extract shared utilities to smart-contract.utils.ts with clear source/destination naming.
1 parent 222d245 commit 4e0d6e1

File tree

6 files changed

+43
-29
lines changed

6 files changed

+43
-29
lines changed

src/app/assets/assets.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ <h3>
176176
title='{{ t("assetsComponent.buttons.send") }}'>
177177
<mat-icon>send</mat-icon>
178178
</button>
179-
<button *ngIf="canTransferRights(group)" mat-icon-button class="icon-color-link" (click)="openTransferRightsForm(group)"
179+
<button *ngIf="showTransferRightsButton(group)" mat-icon-button class="icon-color-link" (click)="openTransferRightsForm(group)"
180180
title='{{ t("assetsComponent.buttons.transferRights") }}'>
181181
<mat-icon svgIcon="transfer_rights"></mat-icon>
182182
</button>

src/app/assets/assets.component.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ 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 } from '../constants/qubic.constants';
27+
import { canSendTransferRights } from '../utils/smart-contract.utils';
2728

2829
// Interfaces for asset grouping
2930
interface GroupedAsset {
@@ -676,23 +677,16 @@ export class AssetsComponent implements OnInit, OnDestroy {
676677
}
677678

678679
/**
679-
* Check if a grouped asset supports transfer rights
680-
* Transfer rights are available for assets with balance > 0 in contracts that support it
681-
* Dynamically checks based on procedure name from backend
680+
* Check if a grouped asset can show the transfer rights button.
681+
* The source contract must have the procedure and the user must own shares.
682682
*/
683-
canTransferRights(group: GroupedAsset): boolean {
684-
// Check if any managing contract in this group supports transfer rights
683+
showTransferRightsButton(group: GroupedAsset): boolean {
685684
return group.managingContracts.some((mc: ManagingContract) => {
686685
const contract = this.smartContractsMap.get(mc.contractIndex);
687686
if (!contract) return false;
688687

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;
688+
// Source contract must have the procedure and user must own shares
689+
return canSendTransferRights(contract) && mc.asset.ownedAmount > 0;
696690
});
697691
}
698692

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

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ import { TransactionService } from '../../services/transaction.service';
1717
import { UpdaterService } from '../../services/updater-service';
1818
import { ApiLiveService } from '../../services/apis/live/api.live.service';
1919
import { QubicStaticService } from '../../services/apis/static/qubic-static.service';
20-
import { StaticSmartContract, SmartContractProcedure } from '../../services/apis/static/qubic-static.model';
20+
import { StaticSmartContract } from '../../services/apis/static/qubic-static.model';
2121

2222
import { QubicTransaction } from '@qubic-lib/qubic-ts-library/dist/qubic-types/QubicTransaction';
2323
import { QubicDefinitions } from '@qubic-lib/qubic-ts-library/dist/QubicDefinitions';
2424
import { PublicKey } from '@qubic-lib/qubic-ts-library/dist/qubic-types/PublicKey';
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 { findTransferRightsProcedure, canReceiveTransferRights } from '../../utils/smart-contract.utils';
2929

3030
/**
3131
* Interface for contracts that can manage assets
@@ -279,8 +279,8 @@ export class TransferRightsComponent implements OnInit, OnDestroy {
279279
continue;
280280
}
281281

282-
// Check if contract supports transfer rights
283-
const procedure = this.findTransferRightsProcedure(contract);
282+
// Check if contract has the transfer rights procedure
283+
const procedure = findTransferRightsProcedure(contract);
284284
if (!procedure) {
285285
continue;
286286
}
@@ -373,9 +373,11 @@ 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 allow transfer shares and have the procedure
377377
for (const [contractIndex, contract] of this.smartContractsMap.entries()) {
378-
const procedure = this.findTransferRightsProcedure(contract);
378+
if (!canReceiveTransferRights(contract)) continue;
379+
380+
const procedure = findTransferRightsProcedure(contract);
379381

380382
if (procedure) {
381383
// Validate procedure fee exists and is valid
@@ -403,15 +405,6 @@ export class TransferRightsComponent implements OnInit, OnDestroy {
403405
this.filteredDestinationContracts = this.destinationContracts;
404406
}
405407

406-
/**
407-
* Find transfer rights procedure in a contract
408-
* Uses dynamic procedure name from constants
409-
*/
410-
private findTransferRightsProcedure(contract: StaticSmartContract): SmartContractProcedure | null {
411-
return contract.procedures.find(p =>
412-
p.name === TRANSFER_SHARE_MANAGEMENT_RIGHTS_PROCEDURE
413-
) ?? null;
414-
}
415408

416409
/**
417410
* Handle source contract selection change

src/app/constants/qubic.constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ 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+

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 {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { SmartContractProcedure, StaticSmartContract } from '../services/apis/static/qubic-static.model';
2+
import { TRANSFER_SHARE_MANAGEMENT_RIGHTS_PROCEDURE } from '../constants/qubic.constants';
3+
4+
/**
5+
* Find the Transfer Share Management Rights procedure in a contract.
6+
*/
7+
export function findTransferRightsProcedure(contract: StaticSmartContract): SmartContractProcedure | null {
8+
return contract.procedures.find(p =>
9+
p.name.toLowerCase() === TRANSFER_SHARE_MANAGEMENT_RIGHTS_PROCEDURE.toLowerCase()
10+
) ?? null;
11+
}
12+
13+
/**
14+
* Check if a smart contract can send transfer rights (used as source).
15+
*/
16+
export function canSendTransferRights(contract: StaticSmartContract): boolean {
17+
return !!findTransferRightsProcedure(contract);
18+
}
19+
20+
/**
21+
* Check if a smart contract can receive transfer rights (used as destination).
22+
*/
23+
export function canReceiveTransferRights(contract: StaticSmartContract): boolean {
24+
return !!contract.allowTransferShares;
25+
}

0 commit comments

Comments
 (0)