Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: removed reliance on caip-api dependency #25

Merged
merged 2 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion examples/dapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"@walletconnect/utils": "2.10.3",
"axios": "^0.21.1",
"blockies-ts": "^1.0.0",
"caip-api": "^2.0.0-beta.1",
"cosmos-wallet": "^1.1.0",
"eth-sig-util": "^2.5.3",
"ethereumjs-util": "^7.0.6",
Expand Down
26 changes: 7 additions & 19 deletions examples/dapp/src/components/Blockchain.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { PropsWithChildren, FC } from "react";
import styled from "styled-components";
import { ChainData } from "caip-api";

import Asset from "./Asset";
import Button from "./Button";
Expand All @@ -14,6 +13,7 @@ import {
ChainMetadata,
ChainNamespaces,
AccountBalances,
NamespaceMetadata,
} from "../helpers";
import { fonts } from "../styles";

Expand Down Expand Up @@ -93,13 +93,13 @@ interface BlockchainProps {
}

interface BlockchainDisplayData {
data: ChainData;
data: ChainMetadata;
meta: ChainMetadata;
}

function getBlockchainDisplayData(
chainId: string,
chainData: ChainNamespaces
chainData: ChainNamespaces,
): BlockchainDisplayData | undefined {
const [namespace, reference] = chainId.split(":");
let meta: ChainMetadata;
Expand All @@ -108,24 +108,15 @@ function getBlockchainDisplayData(
} catch (e) {
return undefined;
}
const data: ChainData = chainData[namespace][reference];
const data = chainData[namespace][reference];
if (typeof data === "undefined") return undefined;
return { data, meta };
}

const Blockchain: FC<PropsWithChildren<BlockchainProps>> = (
props: PropsWithChildren<BlockchainProps>
props: PropsWithChildren<BlockchainProps>,
) => {
const {
chainData,
fetching,
chainId,
address,
onClick,
balances,
active,
actions,
} = props;
const { chainData, fetching, chainId, address, onClick, balances, active, actions } = props;

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

Expand Down Expand Up @@ -162,10 +153,7 @@ const Blockchain: FC<PropsWithChildren<BlockchainProps>> = (
<SFullWidthContainer>
<h6>Balances</h6>
<Column center>
<Asset
key={balances[address].symbol}
asset={balances[address]}
/>
<Asset key={balances[address].symbol} asset={balances[address]} />
</Column>
</SFullWidthContainer>
) : null}
Expand Down
19 changes: 4 additions & 15 deletions examples/dapp/src/contexts/ClientContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
useState,
} from "react";

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

const loadChainData = async () => {
const namespaces = getAllChainNamespaces();
const chainData: ChainNamespaces = {};
await Promise.all(
namespaces.map(async (namespace) => {
let chains: ChainsMap | undefined;
try {
chains = await apiGetChainNamespace(namespace);
} catch (e) {
// ignore error
}
if (typeof chains !== "undefined") {
chainData[namespace] = chains;
}
}),
);
const namespace = namespaces[0];
const chainData = {
[namespace]: EIP155Metadata,
};
setChainData(chainData);
};

Expand Down
4 changes: 1 addition & 3 deletions examples/dapp/src/helpers/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { ChainsMap } from "caip-api";

export interface AssetData {
account: string;
symbol: string;
Expand Down Expand Up @@ -145,7 +143,7 @@ export interface NamespaceMetadata {
[reference: string]: ChainMetadata;
}
export interface ChainNamespaces {
[namespace: string]: ChainsMap;
[namespace: string]: NamespaceMetadata;
}

export interface AccountAction {
Expand Down
21 changes: 0 additions & 21 deletions examples/dapp/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1880,13 +1880,6 @@
"@jridgewell/resolve-uri" "3.1.0"
"@jridgewell/sourcemap-codec" "1.4.14"

"@json-rpc-tools/types@^2.0.0-beta.0":
version "2.0.0-beta.12"
resolved "https://registry.yarnpkg.com/@json-rpc-tools/types/-/types-2.0.0-beta.12.tgz#358f77c48a844a3f55169c2db3b35c6af1cf4e8b"
integrity sha512-UM8w0RnD4DjYql/HlThe051ivW2Q8ulWarr7ux5Aas1UsOmcGQEg4slQo46p+BXgh1Nth7SHWS2tVnW/UUnCwQ==
dependencies:
keyvaluestorage-interface "^1.0.0"

"@lit-labs/ssr-dom-shim@^1.0.0", "@lit-labs/ssr-dom-shim@^1.1.0":
version "1.1.1"
resolved "https://registry.yarnpkg.com/@lit-labs/ssr-dom-shim/-/ssr-dom-shim-1.1.1.tgz#64df34e2f12e68e78ac57e571d25ec07fa460ca9"
Expand Down Expand Up @@ -4482,20 +4475,6 @@ cache-base@^1.0.1:
union-value "^1.0.0"
unset-value "^1.0.0"

caip-api@^2.0.0-beta.1:
version "2.0.0-beta.1"
resolved "https://registry.yarnpkg.com/caip-api/-/caip-api-2.0.0-beta.1.tgz#23877b880396f855fc2cd7892d02c597f2d62ba7"
integrity sha512-pwVXYfAIV3V0QhsKfvamIvsnn7lSmrotukmbXndOE2EsA0dos5W8MLadlpG2U+VSDghCVWI6cY9oJbBuXWj2gg==
dependencies:
"@json-rpc-tools/types" "^2.0.0-beta.0"
axios "^0.21.1"
caip "^0.9.2"

caip@^0.9.2:
version "0.9.2"
resolved "https://registry.yarnpkg.com/caip/-/caip-0.9.2.tgz#6aec668e459dc3a1830530f7bb8d06f0044a5391"
integrity sha512-o4aIUSR9lkn7B9lIw8Xgkj+hDh+S1PtsBphoSqP2Dt95gRWPniaqEpnPwiUEhaPQr84JzWIEm4Cck3lMZtIkTA==

call-bind@^1.0.0, call-bind@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/call-bind/-/call-bind-1.0.2.tgz#b1d4e89e688119c3c9a903ad30abb2f6a919be3c"
Expand Down