Skip to content

Commit

Permalink
add features flag (#1153)
Browse files Browse the repository at this point in the history
  • Loading branch information
cfaur09 authored Nov 24, 2023
1 parent 828258b commit c7f1b47
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/endpoints/network/entities/about.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Field, ObjectType } from "@nestjs/graphql";
import { ApiProperty } from "@nestjs/swagger";
import { FeatureConfigs } from "./feature.configs";

@ObjectType("About", { description: "About object type." })
export class About {
Expand Down Expand Up @@ -30,4 +31,8 @@ export class About {
@Field(() => String, { description: "Scam engine version.", nullable: true })
@ApiProperty({ type: String, nullable: true })
scamEngineVersion: string | undefined = undefined;

@Field(() => FeatureConfigs, { description: "Feature Flags.", nullable: true })
@ApiProperty({ type: FeatureConfigs, nullable: true })
features: FeatureConfigs | undefined = undefined;
}
25 changes: 25 additions & 0 deletions src/endpoints/network/entities/feature.configs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Field, ObjectType } from "@nestjs/graphql";
import { ApiProperty } from "@nestjs/swagger";

@ObjectType("FeatureConfigs", { description: "FeatureConfigs object type." })
export class FeatureConfigs {
constructor(init?: Partial<FeatureConfigs>) {
Object.assign(this, init);
}

@Field(() => Boolean, { description: "Update Collection Extra Details flag details." })
@ApiProperty({ description: 'Update Collection extra details flag activation value' })
updateCollectionExtraDetails: boolean = false;

@Field(() => Boolean, { description: "Marketplace flag details." })
@ApiProperty({ description: 'Marketplace flag activation value' })
marketplace: boolean = false;

@Field(() => Boolean, { description: "Exchange flag details." })
@ApiProperty({ description: 'Exchange flag activation value' })
exchange: boolean = false;

@Field(() => Boolean, { description: "DataApi flag details." })
@ApiProperty({ description: 'DataApi flag activation value' })
dataApi: boolean = false;
}
9 changes: 9 additions & 0 deletions src/endpoints/network/network.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { SmartContractResultService } from '../sc-results/scresult.service';
import { TokenService } from '../tokens/token.service';
import { AccountFilter } from '../accounts/entities/account.filter';
import { DataApiService } from 'src/common/data-api/data-api.service';
import { FeatureConfigs } from './entities/feature.configs';

@Injectable()
export class NetworkService {
Expand Down Expand Up @@ -332,12 +333,20 @@ export class NetworkService {
}
}

const features = new FeatureConfigs({
updateCollectionExtraDetails: this.apiConfigService.isUpdateCollectionExtraDetailsEnabled(),
marketplace: this.apiConfigService.isMarketplaceFeatureEnabled(),
exchange: this.apiConfigService.isExchangeEnabled(),
dataApi: this.apiConfigService.isDataApiFeatureEnabled(),
});

const about = new About({
appVersion,
pluginsVersion,
network: this.apiConfigService.getNetwork(),
cluster: this.apiConfigService.getCluster(),
version: apiVersion,
features: features,
});

await this.pluginService.processAbout(about);
Expand Down
15 changes: 15 additions & 0 deletions src/test/unit/services/network.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ describe('NetworkService', () => {
getMetaChainShardId: jest.fn(),
getAuctionContractAddress: jest.fn(),
getDelegationContractAddress: jest.fn(),
isUpdateCollectionExtraDetailsEnabled: jest.fn(),
isMarketplaceFeatureEnabled: jest.fn(),
isExchangeEnabled: jest.fn(),
isDataApiFeatureEnabled: jest.fn(),
},
},
{
Expand Down Expand Up @@ -338,6 +342,12 @@ describe('NetworkService', () => {
cluster: undefined,
version: '',
scamEngineVersion: '1.0.0',
features: {
updateCollectionExtraDetails: false,
marketplace: true,
exchange: true,
dataApi: true,
},
};
jest
.spyOn(networkService['cachingService'], 'getOrSet')
Expand All @@ -357,6 +367,11 @@ describe('NetworkService', () => {
});
}));

jest.spyOn(apiConfigService, 'isUpdateCollectionExtraDetailsEnabled').mockReturnValue(false);
jest.spyOn(apiConfigService, 'isMarketplaceFeatureEnabled').mockReturnValue(true);
jest.spyOn(apiConfigService, 'isExchangeEnabled').mockReturnValue(true);
jest.spyOn(apiConfigService, 'isDataApiFeatureEnabled').mockReturnValue(true);

const result = await networkService.getAbout();
expect(result).toStrictEqual(expectedValues);
});
Expand Down

0 comments on commit c7f1b47

Please sign in to comment.