Skip to content

Commit 6c1bf27

Browse files
fix: lint for universal-tezos-provider
1 parent a60e1b9 commit 6c1bf27

File tree

3 files changed

+46
-18
lines changed

3 files changed

+46
-18
lines changed

dapps/universal-provider-tezos/src/App.tsx

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ import {
99
formatTezosBalance,
1010
getAccounts,
1111
getChainId,
12-
apiGetContractAddress
12+
apiGetContractAddress,
13+
TezosSendResponse,
14+
TezosSignResponse,
15+
TezosGetAccountResponse
1316
} from './utils/helpers'
1417
import { SAMPLE_KINDS, SAMPLES } from './utils/samples'
1518

@@ -26,9 +29,13 @@ const methods = ['tezos_getAccounts', 'tezos_sign', 'tezos_send']
2629
const App = () => {
2730
const [provider, setProvider] = useState<UniversalProvider | null>(null)
2831
const [isConnected, setIsConnected] = useState(false)
29-
const [lastKind, setLastKind] = useState<any>(null)
30-
const [result, setResult] = useState<any>(null)
31-
const [description, setDescription] = useState<any>(null)
32+
const [lastKind, setLastKind] = useState<SAMPLE_KINDS | undefined>(undefined)
33+
const [result, setResult] = useState<
34+
TezosSendResponse | TezosSignResponse | TezosGetAccountResponse | string | null
35+
>(null)
36+
const [description, setDescription] = useState<Record<string, unknown> | string | undefined>(
37+
undefined
38+
)
3239
const [balance, setBalance] = useState('')
3340
const [address, setAddress] = useState('')
3441
const [contractAddress, setContractAddress] = useState(
@@ -68,7 +75,7 @@ const App = () => {
6875
console.log('Session Ping:', id, topic)
6976
})
7077

71-
newProvider.on('session_event', ({ event, chainId }: { event: any; chainId: string }) => {
78+
newProvider.on('session_event', ({ event, chainId }: { event: unknown; chainId: string }) => {
7279
console.log('Session Event:', event, chainId)
7380
})
7481

@@ -205,7 +212,7 @@ const App = () => {
205212
await getBalance()
206213
} catch (error) {
207214
console.error(`Error sending ${kind}:`, error)
208-
setResult(error)
215+
setResult(JSON.stringify(error, null, 2))
209216
}
210217
},
211218
[provider, address]
@@ -223,9 +230,11 @@ const App = () => {
223230
case SAMPLE_KINDS.SEND_TRANSACTION:
224231
case SAMPLE_KINDS.SEND_DELEGATION:
225232
case SAMPLE_KINDS.SEND_UNDELEGATION:
226-
case SAMPLE_KINDS.SEND_ORGINATION:
227233
setDescription(SAMPLES[kind])
228234
break
235+
case SAMPLE_KINDS.SEND_ORGINATION:
236+
setDescription(SAMPLES[kind] as unknown as Record<string, unknown>)
237+
break
229238
case SAMPLE_KINDS.SEND_CONTRACT_CALL:
230239
case SAMPLE_KINDS.SEND_INCREASE_PAID_STORAGE:
231240
setDescription({ ...SAMPLES[kind], destination: contractAddress })
@@ -248,7 +257,7 @@ const App = () => {
248257
<div className="App">
249258
<h1>UniversalProvider</h1>
250259
<h2>WalletConnect for Tezos</h2>
251-
<p>dApp prototype integrating WalletConnect's Tezos Universal Provider.</p>
260+
<p>dApp prototype integrating for Tezos Universal Provider.</p>
252261

253262
{!projectId || projectId === 'YOUR_PROJECT_ID' ? (
254263
<div className="warning">

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

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ export interface AssetData {
2020
balance: number
2121
}
2222

23+
interface Operation {
24+
status?: string
25+
originatedContract?: {
26+
kind: string
27+
address: string
28+
}
29+
}
30+
2331
export interface ChainData {
2432
name: string
2533
id: string
@@ -51,6 +59,19 @@ export const TezosChainData: ChainsMap = {
5159
}
5260
}
5361

62+
export interface TezosGetAccountsData {
63+
algo: string
64+
address: string
65+
pubkey: string
66+
}
67+
export type TezosGetAccountResponse = TezosGetAccountsData[]
68+
export interface TezosSignResponse {
69+
signature: string
70+
}
71+
export interface TezosSendResponse {
72+
hash: string
73+
}
74+
5475
// Singleton class to manage TezosToolkit instances
5576
class TezosInstanceManager {
5677
private static instances: Map<string, TezosToolkit> = new Map()
@@ -94,7 +115,7 @@ export async function apiGetContractAddress(
94115
chainId: string, // Remove this line if the parameter is not used in the function body.
95116
hash: string
96117
): Promise<string[]> {
97-
const [_, networkId] = chainId.split(':')
118+
const [, networkId] = chainId.split(':')
98119

99120
if (!hash) {
100121
throw new Error(`No hash provided`)
@@ -110,9 +131,9 @@ export async function apiGetContractAddress(
110131

111132
return fetch(path)
112133
.then(response => response.json())
113-
.then(data => {
134+
.then((data: Operation[]) => {
114135
return data
115-
.map((op: any) => {
136+
.map((op: Operation) => {
116137
const address =
117138
op?.status === 'applied' && op?.originatedContract?.kind === 'smart_contract'
118139
? op.originatedContract.address
@@ -134,17 +155,17 @@ export const getAccounts = async (
134155
chainId: string,
135156
provider: UniversalProvider,
136157
address: string
137-
) => {
158+
): Promise<TezosGetAccountResponse> => {
138159
console.log('TezosRpc getAccounts helper: ', chainId, provider, address)
139-
const result = await provider!.request<Array<{ address: string }>>(
160+
const result = await provider!.request<TezosGetAccountsData[]>(
140161
{
141162
method: 'tezos_getAccounts',
142163
params: {}
143164
},
144165
chainId
145166
)
146167

147-
const addresses = result.map((account: { address: any }) => account.address)
168+
const addresses = result.map((account: { address: string }) => account.address)
148169
// setAddresses(addresses);
149170
console.log('TezosRpc received addresses: ', addresses)
150171

@@ -155,7 +176,7 @@ export const signMessage = async (
155176
chainId: string,
156177
provider: UniversalProvider,
157178
address: string
158-
) => {
179+
): Promise<TezosSignResponse> => {
159180
const payload = '05010000004254'
160181
const result = await provider!.request<{ signature: string }>(
161182
{
@@ -176,7 +197,7 @@ export const sendTransaction = async (
176197
provider: UniversalProvider,
177198
address: string,
178199
operation: PartialTezosOperation
179-
) => {
200+
): Promise<TezosSendResponse> => {
180201
console.log('TezosRpc operation: ', operation)
181202
const result = await provider!.request<{ hash: string }>(
182203
{

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,5 +123,3 @@ export const SAMPLES = {
123123
'tezos_send:finalize': tezosFinalizeOperation,
124124
'tezos_send:increase_paid_storage': TezosIncreasePaidStorageOperation
125125
}
126-
127-
export enum DEFAULT_TEZOS_EVENTS {}

0 commit comments

Comments
 (0)