Skip to content
This repository was archived by the owner on Apr 11, 2025. It is now read-only.

Commit 28fc422

Browse files
authored
Merge pull request #25 from WalletConnect/fix/example-dapp-blockchain-api
fix: removed reliance on `caip-api` dependency
2 parents 54d4027 + 936f10a commit 28fc422

File tree

5 files changed

+12
-59
lines changed

5 files changed

+12
-59
lines changed

examples/dapp/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
"@walletconnect/utils": "2.10.3",
3737
"axios": "^0.21.1",
3838
"blockies-ts": "^1.0.0",
39-
"caip-api": "^2.0.0-beta.1",
4039
"cosmos-wallet": "^1.1.0",
4140
"eth-sig-util": "^2.5.3",
4241
"ethereumjs-util": "^7.0.6",

examples/dapp/src/components/Blockchain.tsx

+7-19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React, { PropsWithChildren, FC } from "react";
22
import styled from "styled-components";
3-
import { ChainData } from "caip-api";
43

54
import Asset from "./Asset";
65
import Button from "./Button";
@@ -14,6 +13,7 @@ import {
1413
ChainMetadata,
1514
ChainNamespaces,
1615
AccountBalances,
16+
NamespaceMetadata,
1717
} from "../helpers";
1818
import { fonts } from "../styles";
1919

@@ -93,13 +93,13 @@ interface BlockchainProps {
9393
}
9494

9595
interface BlockchainDisplayData {
96-
data: ChainData;
96+
data: ChainMetadata;
9797
meta: ChainMetadata;
9898
}
9999

100100
function getBlockchainDisplayData(
101101
chainId: string,
102-
chainData: ChainNamespaces
102+
chainData: ChainNamespaces,
103103
): BlockchainDisplayData | undefined {
104104
const [namespace, reference] = chainId.split(":");
105105
let meta: ChainMetadata;
@@ -108,24 +108,15 @@ function getBlockchainDisplayData(
108108
} catch (e) {
109109
return undefined;
110110
}
111-
const data: ChainData = chainData[namespace][reference];
111+
const data = chainData[namespace][reference];
112112
if (typeof data === "undefined") return undefined;
113113
return { data, meta };
114114
}
115115

116116
const Blockchain: FC<PropsWithChildren<BlockchainProps>> = (
117-
props: PropsWithChildren<BlockchainProps>
117+
props: PropsWithChildren<BlockchainProps>,
118118
) => {
119-
const {
120-
chainData,
121-
fetching,
122-
chainId,
123-
address,
124-
onClick,
125-
balances,
126-
active,
127-
actions,
128-
} = props;
119+
const { chainData, fetching, chainId, address, onClick, balances, active, actions } = props;
129120

130121
if (!Object.keys(chainData).length) return null;
131122

@@ -162,10 +153,7 @@ const Blockchain: FC<PropsWithChildren<BlockchainProps>> = (
162153
<SFullWidthContainer>
163154
<h6>Balances</h6>
164155
<Column center>
165-
<Asset
166-
key={balances[address].symbol}
167-
asset={balances[address]}
168-
/>
156+
<Asset key={balances[address].symbol} asset={balances[address]} />
169157
</Column>
170158
</SFullWidthContainer>
171159
) : null}

examples/dapp/src/contexts/ClientContext.tsx

+4-15
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
useState,
99
} from "react";
1010

11-
import { apiGetChainNamespace, ChainsMap } from "caip-api";
1211
import { PairingTypes, SessionTypes } from "@walletconnect/types";
1312
import { EthereumProvider } from "@walletconnect/ethereum-provider";
1413
import type IEthereumProvider from "@walletconnect/ethereum-provider";
@@ -79,20 +78,10 @@ export function ClientContextProvider({ children }: { children: ReactNode | Reac
7978

8079
const loadChainData = async () => {
8180
const namespaces = getAllChainNamespaces();
82-
const chainData: ChainNamespaces = {};
83-
await Promise.all(
84-
namespaces.map(async (namespace) => {
85-
let chains: ChainsMap | undefined;
86-
try {
87-
chains = await apiGetChainNamespace(namespace);
88-
} catch (e) {
89-
// ignore error
90-
}
91-
if (typeof chains !== "undefined") {
92-
chainData[namespace] = chains;
93-
}
94-
}),
95-
);
81+
const namespace = namespaces[0];
82+
const chainData = {
83+
[namespace]: EIP155Metadata,
84+
};
9685
setChainData(chainData);
9786
};
9887

examples/dapp/src/helpers/types.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { ChainsMap } from "caip-api";
2-
31
export interface AssetData {
42
account: string;
53
symbol: string;
@@ -145,7 +143,7 @@ export interface NamespaceMetadata {
145143
[reference: string]: ChainMetadata;
146144
}
147145
export interface ChainNamespaces {
148-
[namespace: string]: ChainsMap;
146+
[namespace: string]: NamespaceMetadata;
149147
}
150148

151149
export interface AccountAction {

examples/dapp/yarn.lock

-21
Original file line numberDiff line numberDiff line change
@@ -1880,13 +1880,6 @@
18801880
"@jridgewell/resolve-uri" "3.1.0"
18811881
"@jridgewell/sourcemap-codec" "1.4.14"
18821882

1883-
"@json-rpc-tools/types@^2.0.0-beta.0":
1884-
version "2.0.0-beta.12"
1885-
resolved "https://registry.yarnpkg.com/@json-rpc-tools/types/-/types-2.0.0-beta.12.tgz#358f77c48a844a3f55169c2db3b35c6af1cf4e8b"
1886-
integrity sha512-UM8w0RnD4DjYql/HlThe051ivW2Q8ulWarr7ux5Aas1UsOmcGQEg4slQo46p+BXgh1Nth7SHWS2tVnW/UUnCwQ==
1887-
dependencies:
1888-
keyvaluestorage-interface "^1.0.0"
1889-
18901883
"@lit-labs/ssr-dom-shim@^1.0.0", "@lit-labs/ssr-dom-shim@^1.1.0":
18911884
version "1.1.1"
18921885
resolved "https://registry.yarnpkg.com/@lit-labs/ssr-dom-shim/-/ssr-dom-shim-1.1.1.tgz#64df34e2f12e68e78ac57e571d25ec07fa460ca9"
@@ -4482,20 +4475,6 @@ cache-base@^1.0.1:
44824475
union-value "^1.0.0"
44834476
unset-value "^1.0.0"
44844477

4485-
caip-api@^2.0.0-beta.1:
4486-
version "2.0.0-beta.1"
4487-
resolved "https://registry.yarnpkg.com/caip-api/-/caip-api-2.0.0-beta.1.tgz#23877b880396f855fc2cd7892d02c597f2d62ba7"
4488-
integrity sha512-pwVXYfAIV3V0QhsKfvamIvsnn7lSmrotukmbXndOE2EsA0dos5W8MLadlpG2U+VSDghCVWI6cY9oJbBuXWj2gg==
4489-
dependencies:
4490-
"@json-rpc-tools/types" "^2.0.0-beta.0"
4491-
axios "^0.21.1"
4492-
caip "^0.9.2"
4493-
4494-
caip@^0.9.2:
4495-
version "0.9.2"
4496-
resolved "https://registry.yarnpkg.com/caip/-/caip-0.9.2.tgz#6aec668e459dc3a1830530f7bb8d06f0044a5391"
4497-
integrity sha512-o4aIUSR9lkn7B9lIw8Xgkj+hDh+S1PtsBphoSqP2Dt95gRWPniaqEpnPwiUEhaPQr84JzWIEm4Cck3lMZtIkTA==
4498-
44994478
call-bind@^1.0.0, call-bind@^1.0.2:
45004479
version "1.0.2"
45014480
resolved "https://registry.yarnpkg.com/call-bind/-/call-bind-1.0.2.tgz#b1d4e89e688119c3c9a903ad30abb2f6a919be3c"

0 commit comments

Comments
 (0)