Skip to content

Commit

Permalink
[misc] add subtitle (#74)
Browse files Browse the repository at this point in the history
Co-authored-by: Manh Cao <[email protected]>
  • Loading branch information
manh-pendle and Manh Cao authored Dec 9, 2024
1 parent b53a94c commit c2b46b9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
3 changes: 3 additions & 0 deletions const.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ const PROTOCOL_CATEGORIES = ['money market', 'yield strategy', 'liquid locker',

const DESCRIPTION_MAXIMUM_CHARACTERS = 120;

const SUBTITLE_MAXIMUM_CHARACTERS = 12;

module.exports = {
PROTOCOL_CATEGORIES,
DESCRIPTION_MAXIMUM_CHARACTERS,
SUBTITLE_MAXIMUM_CHARACTERS,
}
3 changes: 2 additions & 1 deletion merge-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,13 @@ function formatProtocolConfig(config) {
function formatMetadataAssets(assets) {
const result = [];
for (const asset of (assets ?? [])) {
const {chainId, address, integrationUrl, description} = asset;
const {chainId, address, integrationUrl, description, subtitle} = asset;
result.push({
chainId,
address: address.toLowerCase(),
integrationUrl,
description,
subtitle,
})
}

Expand Down
22 changes: 20 additions & 2 deletions validate-config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const fs = require('fs');
const path = require('path');
const yaml = require('js-yaml');
const {PROTOCOL_CATEGORIES, DESCRIPTION_MAXIMUM_CHARACTERS} = require("./const");
const {PROTOCOL_CATEGORIES, DESCRIPTION_MAXIMUM_CHARACTERS, SUBTITLE_MAXIMUM_CHARACTERS} = require("./const");

const LIMIT_ICON_KB_SIZE = 20;
const BUFFER_LIMIT_ICON_KB_SIZE = LIMIT_ICON_KB_SIZE + 1;
Expand Down Expand Up @@ -34,6 +34,22 @@ function validateDescription(info) {
}
}

function validateSubtitle(info) {
const {protocol, field, index, subtitle} = info;

if (subtitle === undefined) {
return;
}

if (!mustBeNonEmptyString(subtitle)) {
throw new Error(`protocol ${protocol}: metadata ${field} 'subtitle' is not an non-empty string`);
}

if (subtitle.length > SUBTITLE_MAXIMUM_CHARACTERS) {
throw new Error(`protocol ${protocol}: metadata ${field} 'subtitle' too long at index ${index}`);
}
}

async function main() {
const CHANGED_PROTOCOLS = process.env.CHANGED_PROTOCOLS;
const GET_ASSET_LIST_URL = process.env.GET_ASSET_LIST_URL;
Expand Down Expand Up @@ -155,7 +171,7 @@ function checkMetadataField(data, protocol, field, assetMap) {

for (let index = 0; index < data.length; index ++) {
const item = data[index];
const {chainId, address, description, integrationUrl} = item;
const {chainId, address, description, integrationUrl, subtitle} = item;

if (typeof chainId !== 'number') {
throw new Error(`protocol ${protocol}: metadata ${field} invalid 'chainId' field at index ${index}`);
Expand All @@ -171,6 +187,8 @@ function checkMetadataField(data, protocol, field, assetMap) {

validateDescription({protocol, field, index, description});

validateSubtitle({protocol, field, index, subtitle});

if (!mustBeNonEmptyString(integrationUrl)) {
throw new Error(`protocol ${protocol}: metadata ${field} invalid 'integrationUrl' field at index ${index}`);
}
Expand Down

0 comments on commit c2b46b9

Please sign in to comment.