Skip to content

Commit 4636633

Browse files
fix: lint for tezos-provider
1 parent 6abe35b commit 4636633

File tree

4 files changed

+47
-21
lines changed

4 files changed

+47
-21
lines changed

dapps/tezos-provider/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
"prettier:write": "prettier --write '**/*.{js,ts,jsx,tsx}'"
1313
},
1414
"dependencies": {
15-
"@airgap/beacon-types": "^4.2.2",
15+
"@airgap/beacon-types": "^4.3.0",
1616
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
1717
"@solana/web3.js": "^1.78.4",
18+
"@taquito/rpc": "^20.0.1",
1819
"@taquito/taquito": "^20.0.1",
1920
"@walletconnect/modal": "^2.6.2",
2021
"@walletconnect/universal-provider": "^2.14.0",

dapps/tezos-provider/src/App.tsx

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ import { SAMPLES, SAMPLE_KINDS } from "./utils/samples";
44
import TezosProvider, {
55
TezosChainDataMainnet,
66
TezosChainDataTestnet,
7-
} from "@walletconnect/tezos-provider";
7+
} from "./utils/tezos-provider";
8+
import {
9+
TezosGetAccountResponse,
10+
TezosSendResponse,
11+
TezosSignResponse,
12+
} from "./utils/tezos-provider";
813

914
const projectId = import.meta.env.VITE_PROJECT_ID;
1015

@@ -13,9 +18,18 @@ const modal = new WalletConnectModal({ projectId });
1318
const App = () => {
1419
const [provider, setProvider] = useState<TezosProvider | null>(null);
1520
const [isConnected, setIsConnected] = useState(false);
16-
const [lastKind, setLastKind] = useState<SAMPLE_KINDS | null>(null);
17-
const [result, setResult] = useState<any>(null);
18-
const [description, setDescription] = useState<any>(null);
21+
const [lastKind, setLastKind] = useState<SAMPLE_KINDS | undefined>(undefined);
22+
const [result, setResult] = useState<
23+
| TezosSendResponse
24+
| TezosSignResponse
25+
| TezosGetAccountResponse
26+
| string
27+
| string[]
28+
| null
29+
>(null);
30+
const [description, setDescription] = useState<
31+
Record<string, unknown> | string | undefined
32+
>(undefined);
1933
const [contractAddress, setContractAddress] = useState(
2034
"[click Origination to get contract address]",
2135
);
@@ -48,12 +62,12 @@ const App = () => {
4862
);
4963
signer?.on(
5064
"session_event",
51-
({ event, chainId }: { event: any; chainId: string }) =>
65+
({ event, chainId }: { event: unknown; chainId: string }) =>
5266
console.log("Session Event:", event, chainId),
5367
);
5468
signer?.on(
5569
"session_update",
56-
({ event, chainId }: { event: any; chainId: string }) =>
70+
({ event, chainId }: { event: unknown; chainId: string }) =>
5771
console.log("Session Update:", event, chainId),
5872
);
5973

@@ -206,7 +220,7 @@ const App = () => {
206220
setResult([error.name, error.message]);
207221
} else {
208222
console.error(`Error sending ${kind}:`, error);
209-
setResult(error);
223+
setResult(JSON.stringify(error, null, 2));
210224
}
211225
}
212226
},
@@ -220,9 +234,11 @@ const App = () => {
220234
case SAMPLE_KINDS.SEND_TRANSACTION:
221235
case SAMPLE_KINDS.SEND_DELEGATION:
222236
case SAMPLE_KINDS.SEND_UNDELEGATION:
223-
case SAMPLE_KINDS.SEND_ORGINATION:
224237
setDescription(SAMPLES[kind]);
225238
break;
239+
case SAMPLE_KINDS.SEND_ORGINATION:
240+
setDescription(SAMPLES[kind] as unknown as Record<string, unknown>);
241+
break;
226242
case SAMPLE_KINDS.SEND_CONTRACT_CALL:
227243
case SAMPLE_KINDS.SEND_INCREASE_PAID_STORAGE:
228244
setDescription({

dapps/tezos-provider/src/utils/tezos-provider.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { UniversalProvider, Metadata } from "@walletconnect/universal-provider";
22
import { KeyValueStorageOptions } from "@walletconnect/keyvaluestorage";
33
import { Logger } from "@walletconnect/logger";
4+
import { SessionTypes } from "@walletconnect/types";
45
import { TezosToolkit } from "@taquito/taquito";
56
import {
67
PartialTezosDalPublishCommitmentOperation,
@@ -152,6 +153,14 @@ export const DefaultTezosMethods: TezosMethod[] = [
152153
TezosMethod.SEND,
153154
];
154155

156+
interface Operation {
157+
status?: string;
158+
originatedContract?: {
159+
kind: string;
160+
address: string;
161+
};
162+
}
163+
155164
class TezosProviderError extends Error {
156165
constructor(message: string) {
157166
super(message);
@@ -225,7 +234,7 @@ class TezosProvider {
225234
methods: DefaultTezosMethods,
226235
events: [],
227236
},
228-
): Promise<any> {
237+
): Promise<SessionTypes.Struct | undefined> {
229238
if (!this.signer || !this.config) {
230239
throw new TezosInitializationError();
231240
}
@@ -241,7 +250,7 @@ class TezosProvider {
241250
return acc;
242251
}, {} as ChainsMap);
243252

244-
let res = await this.signer.connect({
253+
const res = await this.signer.connect({
245254
namespaces: {
246255
tezos: {
247256
chains: opts.chains.map((chain) => chain.id),
@@ -258,7 +267,7 @@ class TezosProvider {
258267

259268
// Set the address if the session exists
260269
if (this.signer.session) {
261-
let accounts =
270+
const accounts =
262271
this.signer.session.namespaces.tezos?.accounts.map(
263272
(account) => account.split(":")[2],
264273
) ?? [];
@@ -306,9 +315,9 @@ class TezosProvider {
306315
};
307316
}
308317

309-
public async getFormattedBalance(): Promise<string> {
310-
const balance = await this.getBalance();
311-
return `${balance.balance.toFixed(6)}`;
318+
static formatTezosBalance(asset: AssetData): string {
319+
const formattedBalance = (asset.balance / 1_000_000).toFixed(6);
320+
return `${asset.name}: ${formattedBalance} ${asset.symbol}`;
312321
}
313322

314323
public async getContractAddress(hash: string): Promise<string[]> {
@@ -322,9 +331,9 @@ class TezosProvider {
322331

323332
return fetch(path)
324333
.then((response) => response.json())
325-
.then((data) => {
334+
.then((data: Operation[]) => {
326335
return data
327-
.map((op: any) => {
336+
.map((op: Operation) => {
328337
const address =
329338
op?.status === "applied" &&
330339
op?.originatedContract?.kind === "smart_contract"

dapps/tezos-provider/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
resolved "https://registry.yarnpkg.com/@aashutoshrathi/word-wrap/-/word-wrap-1.2.6.tgz#bd9154aec9983f77b3a034ecaa015c2e4201f6cf"
88
integrity sha512-1Yjs2SvM8TflER/OD3cOjhWWOZb58A2t7wpE2S9XfBYTiIl+XFhQG2bjy4Pu1I+EAlCNUzRDYDdFwFYUKvXcIA==
99

10-
"@airgap/beacon-types@^4.2.2":
11-
version "4.2.2"
12-
resolved "https://registry.yarnpkg.com/@airgap/beacon-types/-/beacon-types-4.2.2.tgz#b239e17270ebc4ffff084ee7d7e50523e62743e6"
13-
integrity sha512-4sX5QEZTanQ5E6FiY7lp6ilv6rlzu5eNrWa3KdygpHm0NFfkJCY7YRPWo4V5LkCCkILa9QF5TS9tVKMORNcocQ==
10+
"@airgap/beacon-types@^4.3.0":
11+
version "4.3.0"
12+
resolved "https://registry.yarnpkg.com/@airgap/beacon-types/-/beacon-types-4.3.0.tgz#7838643405b89ffd26b4f82cb57ec4d474c05e5c"
13+
integrity sha512-mHhjt9BM1I05zBiQ2+xv0gAn0eYI+by1YeVDGRoznE5YRpUGYNr307oYF08pQ7KfPlNbCSDPq295uOHHFuYPfA==
1414
dependencies:
1515
"@types/chrome" "0.0.246"
1616

0 commit comments

Comments
 (0)