Skip to content

Commit

Permalink
improving logo deserialisation
Browse files Browse the repository at this point in the history
  • Loading branch information
pellicceama committed Nov 1, 2022
1 parent cefec0b commit 64b49e9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/model/ChainObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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);

Expand Down
14 changes: 8 additions & 6 deletions src/model/Logos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ export class Logos {
png?: string;
svg?: string;

constructor(input?: LogoDownloadInputs) {
constructor(input?: LogoDownloadInputs | Partial<Logos>) {
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;
}
}
}
Expand Down

0 comments on commit 64b49e9

Please sign in to comment.