summaryrefslogtreecommitdiff
path: root/front/src/components/Sigil.tsx
blob: 4978a72a08eeb72108d2bab085d461593d40b342 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import comet from "@/assets/icons/comet.svg";
import { auraToHex } from "@/logic/utils";
import { isValidPatp } from "urbit-ob";
import { sigil } from "urbit-sigils";
import { reactRenderer } from "urbit-sigils";

interface SigilProps {
  patp: string;
  size: number;
  color?: string;
}

const Sigil = (props: SigilProps) => {
  const color = props.color ? auraToHex(props.color) : "black";
  if (!isValidPatp(props.patp)) return <div className="sigil bad-sigil">X</div>;
  else if (props.patp.length > 28)
    return (
      <img
        className="comet-icon"
        src={comet}
        alt=""
        style={{ width: `${props.size}px`, height: `${props.size}px` }}
      />
    );
  else if (props.patp.length > 15)
    // moons
    return (
      <>
        {sigil({
          patp: props.patp.substring(props.patp.length - 13),
          renderer: reactRenderer,
          size: props.size,
          colors: ["grey", "white"],
        })}
      </>
    );
  else
    return (
      <>
        {sigil({
          patp: props.patp,
          renderer: reactRenderer,
          size: props.size,
          colors: [color, "white"],
        })}
      </>
    );
};

export default Sigil;