• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

blockcoders / kuma-wallet / ebbd3c69-fda1-4bf1-80ea-77bef87d3d87

pending completion
ebbd3c69-fda1-4bf1-80ea-77bef87d3d87

Pull #8

circleci

Ruben
fix tests
Pull Request #8: Milestone 2

876 of 1103 branches covered (79.42%)

Branch coverage included in aggregate %.

3452 of 3452 new or added lines in 44 files covered. (100.0%)

6647 of 7185 relevant lines covered (92.51%)

6.69 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.28
/src/storage/entities/Chains.ts
1
import { AccountType } from "@src/accounts/types";
2✔
2
import { MAINNETS, TESTNETS } from "@src/constants/chains";
2✔
3
import BaseEntity from "./BaseEntity";
2✔
4

2✔
5
export type Chain = {
2✔
6
  name: string;
2✔
7
  addressPrefix?: number;
2✔
8
  rpc: {
2✔
9
    wasm?: string;
2✔
10
    evm?: string;
2✔
11
  };
2✔
12
  nativeCurrency: {
2✔
13
    name: string;
2✔
14
    symbol: string;
2✔
15
    decimals: number;
2✔
16
  };
2✔
17
  explorer: {
2✔
18
    evm?: {
2✔
19
      name: string;
2✔
20
      url: string;
2✔
21
    };
2✔
22
    wasm?: {
2✔
23
      name: string;
2✔
24
      url: string;
2✔
25
    };
2✔
26
  };
2✔
27
  logo: string;
2✔
28
  supportedAccounts: AccountType[];
2✔
29
  xcm?: string[];
2✔
30
};
2✔
31

2✔
32
export default class Chains extends BaseEntity {
7✔
33
  mainnets: Chain[];
7✔
34
  testnets: Chain[];
12✔
35
  custom: Chain[];
12✔
36

7✔
37
  private static instance: Chains;
7✔
38

7✔
39
  private constructor() {
7✔
40
    super();
12✔
41
    this.mainnets = MAINNETS;
12✔
42
    this.testnets = TESTNETS;
12✔
43
    this.custom = [];
12✔
44
  }
12✔
45

7✔
46
  public static getInstance() {
7✔
47
    if (!Chains.instance) {
28✔
48
      Chains.instance = new Chains();
10✔
49
    }
10✔
50
    return Chains.instance;
28✔
51
  }
28✔
52

7✔
53
  static async init() {
7✔
54
    await Chains.set<Chains>(Chains.getInstance());
2✔
55
  }
2✔
56

7✔
57
  static async getDefaultValue<Chains>(): Promise<Chains> {
7✔
58
    const defaultChains = Chains.getInstance();
2✔
59
    defaultChains.mainnets = MAINNETS;
2✔
60
    defaultChains.testnets = TESTNETS;
2✔
61
    return defaultChains as Chains;
2✔
62
  }
2✔
63

7✔
64
  static async loadChains(): Promise<void> {
7✔
65
    const stored = await Chains.get<Chains>();
4✔
66
    if (!stored) throw new Error("failed_to_load_chains");
4✔
67
    const chains = Chains.getInstance();
2✔
68
    chains.mainnets = stored.mainnets;
2✔
69
    chains.testnets = stored.testnets;
2✔
70
    chains.custom = stored.custom;
2✔
71
  }
4✔
72

7✔
73
  static async saveCustomChain(chain: Chain) {
7✔
74
    const chains = await Chains.get<Chains>();
6✔
75
    if (!chains) throw new Error("failed_to_save_custom_chain");
6✔
76
    if (chains.isAlreadyAdded(chain)) throw new Error("chain_already_added");
6✔
77
    chains.custom = [...chains.custom, chain];
2✔
78
    await Chains.set<Chains>(chains);
2✔
79
  }
6✔
80

7✔
81
  static async removeCustomChain(chainName: string) {
7✔
82
    const chains = await Chains.get<Chains>();
4✔
83
    if (!chains) throw new Error("failed_to_remove_custom_chain");
4✔
84
    chains.custom = chains.custom.filter((c) => c.name !== chainName);
2✔
85
    await Chains.set<Chains>(chains);
2✔
86
  }
4✔
87

7✔
88
  static async getByName(chainName: string): Promise<Chain | undefined> {
7✔
89
    const chains = await Chains.get<Chains>();
10✔
90
    if (!chains) throw new Error("failed_to_get_chain_by_name");
10✔
91
    const chain = chains.mainnets.find((c) => c.name === chainName);
8✔
92
    if (chain) return chain;
10✔
93
    const testnet = chains.testnets.find((c) => c.name === chainName);
6✔
94
    if (testnet) return testnet;
10✔
95
    const custom = chains.custom.find((c) => c.name === chainName);
4✔
96
    if (custom) return custom;
10✔
97
    return undefined;
2✔
98
  }
10✔
99

7✔
100
  getAll() {
7✔
101
    return [
2✔
102
      ...this.mainnets,
2✔
103
      ...this.testnets,
2✔
104
      ...this.custom,
2✔
105
    ];
2✔
106
  }
2✔
107

7✔
108
  isAlreadyAdded(chain: Chain) {
7✔
109
    return (
2✔
110
      this.mainnets.some((c) => c.name === chain.name) ||
2!
111
      this.testnets.some((c) => c.name === chain.name) ||
×
112
      this.custom.some((c) => c.name === chain.name)
×
113
    );
2✔
114
  }
2✔
115
}
7✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc