Skip to content

Commit

Permalink
fix: lint for universal-tezos-provider
Browse files Browse the repository at this point in the history
  • Loading branch information
dianasavvatina committed Sep 19, 2024
1 parent a60e1b9 commit 6c1bf27
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 18 deletions.
25 changes: 17 additions & 8 deletions dapps/universal-provider-tezos/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import {
formatTezosBalance,
getAccounts,
getChainId,
apiGetContractAddress
apiGetContractAddress,
TezosSendResponse,
TezosSignResponse,
TezosGetAccountResponse
} from './utils/helpers'
import { SAMPLE_KINDS, SAMPLES } from './utils/samples'

Expand All @@ -26,9 +29,13 @@ const methods = ['tezos_getAccounts', 'tezos_sign', 'tezos_send']
const App = () => {
const [provider, setProvider] = useState<UniversalProvider | null>(null)
const [isConnected, setIsConnected] = useState(false)
const [lastKind, setLastKind] = useState<any>(null)
const [result, setResult] = useState<any>(null)
const [description, setDescription] = useState<any>(null)
const [lastKind, setLastKind] = useState<SAMPLE_KINDS | undefined>(undefined)
const [result, setResult] = useState<
TezosSendResponse | TezosSignResponse | TezosGetAccountResponse | string | null
>(null)
const [description, setDescription] = useState<Record<string, unknown> | string | undefined>(
undefined
)
const [balance, setBalance] = useState('')
const [address, setAddress] = useState('')
const [contractAddress, setContractAddress] = useState(
Expand Down Expand Up @@ -68,7 +75,7 @@ const App = () => {
console.log('Session Ping:', id, topic)
})

newProvider.on('session_event', ({ event, chainId }: { event: any; chainId: string }) => {
newProvider.on('session_event', ({ event, chainId }: { event: unknown; chainId: string }) => {
console.log('Session Event:', event, chainId)
})

Expand Down Expand Up @@ -205,7 +212,7 @@ const App = () => {
await getBalance()
} catch (error) {
console.error(`Error sending ${kind}:`, error)
setResult(error)
setResult(JSON.stringify(error, null, 2))
}
},
[provider, address]
Expand All @@ -223,9 +230,11 @@ const App = () => {
case SAMPLE_KINDS.SEND_TRANSACTION:
case SAMPLE_KINDS.SEND_DELEGATION:
case SAMPLE_KINDS.SEND_UNDELEGATION:
case SAMPLE_KINDS.SEND_ORGINATION:
setDescription(SAMPLES[kind])
break
case SAMPLE_KINDS.SEND_ORGINATION:
setDescription(SAMPLES[kind] as unknown as Record<string, unknown>)
break
case SAMPLE_KINDS.SEND_CONTRACT_CALL:
case SAMPLE_KINDS.SEND_INCREASE_PAID_STORAGE:
setDescription({ ...SAMPLES[kind], destination: contractAddress })
Expand All @@ -248,7 +257,7 @@ const App = () => {
<div className="App">
<h1>UniversalProvider</h1>
<h2>WalletConnect for Tezos</h2>
<p>dApp prototype integrating WalletConnect's Tezos Universal Provider.</p>
<p>dApp prototype integrating for Tezos Universal Provider.</p>

{!projectId || projectId === 'YOUR_PROJECT_ID' ? (
<div className="warning">
Expand Down
37 changes: 29 additions & 8 deletions dapps/universal-provider-tezos/src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ export interface AssetData {
balance: number
}

interface Operation {
status?: string
originatedContract?: {
kind: string
address: string
}
}

export interface ChainData {
name: string
id: string
Expand Down Expand Up @@ -51,6 +59,19 @@ export const TezosChainData: ChainsMap = {
}
}

export interface TezosGetAccountsData {
algo: string
address: string
pubkey: string
}
export type TezosGetAccountResponse = TezosGetAccountsData[]
export interface TezosSignResponse {
signature: string
}
export interface TezosSendResponse {
hash: string
}

// Singleton class to manage TezosToolkit instances
class TezosInstanceManager {
private static instances: Map<string, TezosToolkit> = new Map()
Expand Down Expand Up @@ -94,7 +115,7 @@ export async function apiGetContractAddress(
chainId: string, // Remove this line if the parameter is not used in the function body.
hash: string
): Promise<string[]> {
const [_, networkId] = chainId.split(':')
const [, networkId] = chainId.split(':')

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

return fetch(path)
.then(response => response.json())
.then(data => {
.then((data: Operation[]) => {
return data
.map((op: any) => {
.map((op: Operation) => {
const address =
op?.status === 'applied' && op?.originatedContract?.kind === 'smart_contract'
? op.originatedContract.address
Expand All @@ -134,17 +155,17 @@ export const getAccounts = async (
chainId: string,
provider: UniversalProvider,
address: string
) => {
): Promise<TezosGetAccountResponse> => {
console.log('TezosRpc getAccounts helper: ', chainId, provider, address)
const result = await provider!.request<Array<{ address: string }>>(
const result = await provider!.request<TezosGetAccountsData[]>(
{
method: 'tezos_getAccounts',
params: {}
},
chainId
)

const addresses = result.map((account: { address: any }) => account.address)
const addresses = result.map((account: { address: string }) => account.address)
// setAddresses(addresses);
console.log('TezosRpc received addresses: ', addresses)

Expand All @@ -155,7 +176,7 @@ export const signMessage = async (
chainId: string,
provider: UniversalProvider,
address: string
) => {
): Promise<TezosSignResponse> => {
const payload = '05010000004254'
const result = await provider!.request<{ signature: string }>(
{
Expand All @@ -176,7 +197,7 @@ export const sendTransaction = async (
provider: UniversalProvider,
address: string,
operation: PartialTezosOperation
) => {
): Promise<TezosSendResponse> => {
console.log('TezosRpc operation: ', operation)
const result = await provider!.request<{ hash: string }>(
{
Expand Down
2 changes: 0 additions & 2 deletions dapps/universal-provider-tezos/src/utils/samples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,3 @@ export const SAMPLES = {
'tezos_send:finalize': tezosFinalizeOperation,
'tezos_send:increase_paid_storage': TezosIncreasePaidStorageOperation
}

export enum DEFAULT_TEZOS_EVENTS {}

0 comments on commit 6c1bf27

Please sign in to comment.