From 64b49e97ae36fe4d22cdbda5a2e885de8899bdd9 Mon Sep 17 00:00:00 2001 From: Amadeo Pellicce Date: Tue, 1 Nov 2022 14:58:10 +0100 Subject: [PATCH] improving logo deserialisation --- src/model/ChainObject.ts | 6 +++--- src/model/Logos.ts | 14 ++++++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/model/ChainObject.ts b/src/model/ChainObject.ts index 32bfb57..66d049a 100644 --- a/src/model/ChainObject.ts +++ b/src/model/ChainObject.ts @@ -41,7 +41,7 @@ export abstract class ChainObject extends RepoObject { this.description = info.description || null; this.links = info.links || getEmptyBaseLinks(); - this.logo = info.logo || new Logos(); + this.logo = info.logo? new Logos(info.logo) : new Logos(); if(!info.name) { throw new Error('name is required to initialise an AssetsRepoObject Passed: ' + JSON.stringify(info)); @@ -59,10 +59,10 @@ export abstract class ChainObject extends RepoObject { deserialise(): string { this.version = this.version.toString(); + this.logo = this.logo? this.logo.deserialise() : null; + let parsed = JSON.parse(JSON.stringify(this)); - parsed.logo = this.logo?.deserialise(); - // sort keys parsed = sortObjectKeys(parsed); diff --git a/src/model/Logos.ts b/src/model/Logos.ts index a866f01..265cff1 100644 --- a/src/model/Logos.ts +++ b/src/model/Logos.ts @@ -18,14 +18,16 @@ export class Logos { png?: string; svg?: string; - constructor(input?: LogoDownloadInputs) { + constructor(input?: LogoDownloadInputs | Partial) { if(input) { - if(input.png && (input.png.url || input.png.ipfs)) { - this.png = input.png.url || input.png.ipfs; - } + if(input.png) { + // @ts-ignore + this.png = input.png instanceof String? input.png : input.png.url || input.png.ipfs; + } - if(input.svg && (input.svg.url || input.svg.ipfs)) { - this.svg = input.svg.url || input.svg.ipfs; + if(input.svg) { + // @ts-ignore + this.svg = input.svg instanceof String ? input.svg : input.svg.url || input.svg.ipfs; } } }