17.0.3 • Published 4 months ago

@consolelabs/mochi-ui v17.0.3

Weekly downloads
-
License
ISC
Repository
-
Last release
4 months ago

Mochi UI

This package includes the basic components that you need to render any Mochi data, generally speaking there are 3 main goal:

  • Render Mochi identity
  • Use components such as balance list, activities, transactions list, etc...
  • Utilize helpers such as text/number formatters, etc...

🚀 Usage

import API from "@consolelabs/mochi-rest";
import UI, { utils } from "@consolelabs/mochi-formatter";
import Redis from "ioredis";

// optionally use redis for better perf
UI.redis = new Redis();

const api = new API({});
api.init().then(() => {
  UI.api = api;
});

const [account, otherAccount] = await UI.resolve(
  Platform.Web,
  profile_id,
  other_profile_id
);

const markdownText = await UI.components.balance({
  /* props */
});

const formattedUsd = utils.formatUsdDigit(23.12563);
console.log(formattedUsd); // "$23.12"

🤖 API

resolve(on: Platform.Web | Platform.Discord | Platform.Telegram, profile_id_A: string, profile_id_B?: string)

const [account, otherAccount] = await UI.resolve(
  Platform.Web, // if you're using UI library on web
  profile_id,
  other_profile_id
);

// or using it on self
const [account] = await UI.resolve(Platform.Web, profile_id);

Takes in a platform that you're rendering on, a pair of profile ids to resolve, profile_id_B defaults to profile_id_A if not passed in. The return value is an object with the following properties

type UsernameFmt = {
  // this value is markdown
  value: string;
  // the id of that platform
  id: string;
  // url of this account
  url: string;
  // same as `value` but in plain text format
  plain: string;
  // in case of invalid account, this will be null
  platform?:
    | Platform.App
    | Platform.Mochi
    | Platform.Discord
    | Platform.Telegram
    | Platform.Twitter
    | Platform.Vault
    | null;
};

Utilities

  • formatUsdDigit(input: string | number | object): string: returns a string representation of the usd value with $ prefix
  • formatPercentDigit(input: string | number | object): string: returns a string representation of the percentage value with % suffix
  • formatTokenDigit(input: string | number | object): string: returns a string representation of the token value
  • formatDigit(options: object): string: the base formatter, the shape of options is:
type Options = {
  value: string | number;
  // how many numbers to keep after decimal point
  fractionDigits?: number;
  // decides whether the result should have commas
  withoutCommas?: boolean;
  // use shorten form e.g. 200,000 -> 200K, $1,234,567,890 -> $1B
  // note that by using this option some precision of number will be lost
  shorten?: boolean;
  // use for very small numbers e.g. 1e-8
  scientificFormat?: boolean;
};

Note: All the format functions except formatDigit follows the same decimal point formatting rule, that is:

  • For percentage value, automatically hide decimal point if value >= 10
  • For USD value, automatically hide decimal point if value >= 100
  • For token value, automatically hide decimal point if value >= 1000

  • In case of having to show decimal point, we only take maximum 2 digits that are not 0 starting from the dot, if both are 0 then take the first digit that is not zero, some examples:

0.02345 -> 0.02
0.2103 -> 0.2
0.00003981 -> 0.0003

components (coming soon)

17.0.3

4 months ago

17.0.2

4 months ago

17.0.1

5 months ago

17.0.0

5 months ago

16.0.6

5 months ago

16.0.5

5 months ago

16.0.4

6 months ago

16.0.3

6 months ago

16.0.2

6 months ago

16.0.1

6 months ago

16.0.0

6 months ago

15.0.6

6 months ago

15.0.5

6 months ago

15.0.4

6 months ago

15.0.3

6 months ago

15.0.2

6 months ago

15.0.1

6 months ago

15.0.0

6 months ago

14.0.2

6 months ago

14.0.1

6 months ago

14.0.0

6 months ago

13.0.0

6 months ago

12.0.1

6 months ago

12.0.0

6 months ago

11.0.0

6 months ago

10.0.35

6 months ago

10.0.34

6 months ago

10.0.33

6 months ago

10.0.32

6 months ago

10.0.30

7 months ago

10.0.29

7 months ago

10.0.28

7 months ago

10.0.27

7 months ago

10.0.26

7 months ago

10.0.25

7 months ago

10.0.24

7 months ago

10.0.23

7 months ago

10.0.22

7 months ago

10.0.21

7 months ago

10.0.20

7 months ago

10.0.19

8 months ago

10.0.18

8 months ago

10.0.17

8 months ago

10.0.16

8 months ago

10.0.15

8 months ago

10.0.14

8 months ago

10.0.13

8 months ago

10.0.12

8 months ago

10.0.11

8 months ago

10.0.10

8 months ago

10.0.9

8 months ago

10.0.8

8 months ago

10.0.7

8 months ago

10.0.5

8 months ago

10.0.4

8 months ago

10.0.3

8 months ago

10.0.2

8 months ago

10.0.1

8 months ago

10.0.0

8 months ago

9.1.22

8 months ago

9.1.21

8 months ago

9.1.20

8 months ago

9.1.19

8 months ago

9.1.18

8 months ago

9.1.17

8 months ago

9.1.16

8 months ago

9.1.15

8 months ago

9.1.14

8 months ago

9.1.13

8 months ago

9.1.12

8 months ago

9.1.11

8 months ago

9.1.10

8 months ago

9.1.9

8 months ago

9.1.8

8 months ago

9.1.7

8 months ago

9.1.6

8 months ago

9.1.5

8 months ago

9.1.4

8 months ago

9.1.3

8 months ago

9.1.2

8 months ago

9.1.1

8 months ago

9.1.0

8 months ago

9.0.2

8 months ago

9.0.1

8 months ago

9.0.0

8 months ago

8.0.0

8 months ago

7.0.1

8 months ago

7.0.0

8 months ago

6.0.2

8 months ago

6.0.1

8 months ago

6.0.0

8 months ago

5.0.0

8 months ago

4.0.7

8 months ago

4.0.6

8 months ago

4.0.5

8 months ago

4.0.4

8 months ago

4.0.3

8 months ago

4.0.2

8 months ago

4.0.1

8 months ago

4.0.0

9 months ago

3.0.0

9 months ago

2.0.1

9 months ago

2.0.0

9 months ago

1.1.0

9 months ago

1.0.4

9 months ago

1.0.3

9 months ago

1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago

0.0.2-rc.5

9 months ago

0.0.2-rc.4

9 months ago

0.0.2-rc.3

9 months ago

0.0.2-rc.2

9 months ago

0.0.2-rc.1

9 months ago