-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
65 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import type { ValidatorJSON } from './schemas' | ||
import { createIdenticon, getIdenticonsParams } from 'identicons-esm' | ||
import { optimize } from 'svgo' | ||
|
||
async function getDefaultBranding(address: string) { | ||
return { | ||
icon: await createIdenticon(address, { format: 'image/svg+xml' }), | ||
accentColor: await getIdenticonsParams(address).then(({ colors: { background: accentColor } }) => accentColor), | ||
hasDefaultIcon: true, | ||
} | ||
} | ||
|
||
export async function getBrandingParameters(address: string, { icon: _icon, accentColor }: ValidatorJSON) { | ||
if (!_icon) | ||
return getDefaultBranding(address) | ||
|
||
// TODO Once the validators have accent colors, re-enable this check | ||
// if (!rest.accentColor) | ||
// throw new Error(`The validator ${address} does have an icon but not an accent color`) | ||
|
||
let icon: string = _icon | ||
|
||
if (icon.startsWith('data:image/svg+xml')) { | ||
icon = optimize(icon, { plugins: [{ name: 'preset-default' }] }).data | ||
} | ||
|
||
return { icon, accentColor: accentColor!, hasDefaultIcon: false } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters