Skip to content

Commit 100a72b

Browse files
authored
Merge pull request #36 from cometh-hq/develop
v2.0.6
2 parents 7f23b9d + 4856390 commit 100a72b

File tree

8 files changed

+63
-46
lines changed

8 files changed

+63
-46
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cometh/connect-sdk-viem",
3-
"version": "2.0.5",
3+
"version": "2.0.6",
44
"main": "dist/index.js",
55
"types": "dist/index.d.ts",
66
"description": "Viem SDK Cometh Connect",
@@ -60,7 +60,7 @@
6060
},
6161
"dependencies": {
6262
"@babel/traverse": "^7.23.4",
63-
"@cometh/connect-sdk": "^1.2.21",
63+
"@cometh/connect-sdk": "^1.2.25",
6464
"@rainbow-me/rainbowkit": "^2",
6565
"@types/babel__core": "^7.20.0",
6666
"viem": "^2",

src/client/getConnectViemClient.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
import { ComethWallet } from '@cometh/connect-sdk'
2-
import {
3-
Account,
4-
Chain,
5-
Client,
6-
createPublicClient,
7-
http,
8-
Transport
9-
} from 'viem'
2+
import { Account, Chain, Client, createClient, http, Transport } from 'viem'
103
import { Prettify } from 'viem/_types/types/utils'
114
import {
125
arbitrum,
@@ -72,17 +65,25 @@ export type ConnectClientParams = {
7265
rpc?: string
7366
}
7467

75-
export const getConnectViemClient = ({
68+
export const getConnectViemClient = <
69+
transport extends Transport = Transport,
70+
chain extends Chain | undefined = Chain | undefined,
71+
account extends Account | undefined = Account | undefined
72+
>({
7673
wallet,
7774
apiKey,
7875
rpc
79-
}: ConnectClientParams): any => {
76+
}: ConnectClientParams): ConnectClient<transport, chain, account> => {
8077
const chain = supportedChains.find(
8178
(chain) => chain.id === wallet.chainId
8279
) as Chain
8380

84-
return createPublicClient({
81+
return createClient({
8582
chain,
8683
transport: http(rpc)
87-
}).extend(connectWalletActions(wallet, apiKey))
84+
}).extend(connectWalletActions(wallet, apiKey)) as unknown as ConnectClient<
85+
transport,
86+
chain,
87+
account
88+
>
8889
}

src/customActions/connectWalletActions.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -299,15 +299,15 @@ export const connectWalletActions =
299299
writeContract: (args) =>
300300
writeContract(client, {...args, wallet } as any),
301301
signMessage: (args) =>
302-
signMessage(client, {
302+
signMessage( {
303303
...args,
304304
wallet
305305
} as SignMessageWithConnectParameters),
306-
simulateContract: (args) =>
307-
simulateContract(client, {
308-
...args,
309-
wallet
310-
} as SimulateContractWithConnectParameters),
306+
simulateContract: (args) =>
307+
simulateContract(client, {
308+
...args,
309+
wallet
310+
} as SimulateContractWithConnectParameters),
311311
verifyMessage: (args) =>
312312
verifyMessage(client, {
313313
...args,
@@ -316,4 +316,6 @@ export const connectWalletActions =
316316
} as VerifyMessageWithConnectParameters)
317317
})
318318

319-
export { getTransaction, sendBatchTransactions, sendTransaction, simulateContract, verifyMessage,writeContract }
319+
320+
321+
export { getTransaction, sendBatchTransactions, sendTransaction, simulateContract, verifyMessage, writeContract }

src/customActions/getTransaction.ts

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
import { ComethWallet } from '@cometh/connect-sdk'
22
import {
3+
Account,
34
Address,
45
Chain,
6+
Client,
7+
createClient,
8+
createPublicClient,
59
GetBlockNumberReturnType,
610
Hash,
11+
Hex,
12+
http,
13+
Log,
714
parseAbiItem,
815
PublicClient,
916
TransactionReceipt,
@@ -13,11 +20,11 @@ import {
1320
import { sleep } from '../utils/utils'
1421

1522
const _catchSuccessEvent = async (
16-
client: PublicClient<Transport, Chain>,
23+
client: PublicClient,
1724
address: Address,
1825
safeTxHash: Hash,
1926
currentBlockNumber: GetBlockNumberReturnType
20-
): Promise<any> => {
27+
): Promise<Log> => {
2128
const successTransactionLogs = await client.getLogs({
2229
address,
2330
event: parseAbiItem(
@@ -30,15 +37,15 @@ const _catchSuccessEvent = async (
3037
(e) => e.args.txHash == safeTxHash
3138
)
3239

33-
return filteredTransactionEvent
40+
return filteredTransactionEvent as Log
3441
}
3542

3643
const _catchFailureEvent = async (
37-
client: PublicClient<Transport, Chain>,
44+
client: PublicClient,
3845
address: Address,
3946
safeTxHash: Hash,
4047
currentBlockNumber: GetBlockNumberReturnType
41-
): Promise<any> => {
48+
): Promise<Log> => {
4249
const successTransactionLogs = await client.getLogs({
4350
address,
4451
event: parseAbiItem(
@@ -51,17 +58,20 @@ const _catchFailureEvent = async (
5158
(e) => e.args.txHash == safeTxHash
5259
)
5360

54-
return filteredTransactionEvent
61+
return filteredTransactionEvent as Log
5562
}
5663

57-
export const getTransaction = async ({
64+
export const getTransaction = async <
65+
TChain extends Chain | undefined,
66+
TAccount extends Account | undefined
67+
>({
5868
client,
5969
wallet,
6070
safeTxHash,
6171
relayId,
6272
timeout = 60 * 1000
6373
}: {
64-
client: any
74+
client: Client<Transport, TChain, TAccount>
6575
wallet: ComethWallet
6676
safeTxHash: Hash
6777
relayId?: string
@@ -70,7 +80,12 @@ export const getTransaction = async ({
7080
const startDate = Date.now()
7181
const timeoutLimit = new Date(startDate + timeout).getTime()
7282

73-
const currentBlockNumber = await client.getBlockNumber()
83+
const publicClient = createPublicClient({
84+
chain: client.chain,
85+
transport: http(client.transport.rpcUrl)
86+
}) as PublicClient
87+
88+
const currentBlockNumber = await publicClient.getBlockNumber()
7489
const from = wallet.getAddress() as Address
7590

7691
let txSuccessEvent
@@ -79,13 +94,13 @@ export const getTransaction = async ({
7994
while (!txSuccessEvent && !txFailureEvent && Date.now() < timeoutLimit) {
8095
await sleep(3000)
8196
txSuccessEvent = await _catchSuccessEvent(
82-
client,
97+
publicClient,
8398
from,
8499
safeTxHash,
85100
currentBlockNumber
86101
)
87102
txFailureEvent = await _catchFailureEvent(
88-
client,
103+
publicClient,
89104
from,
90105
safeTxHash,
91106
currentBlockNumber
@@ -99,8 +114,8 @@ export const getTransaction = async ({
99114

100115
while (txResponse === null) {
101116
try {
102-
txResponse = await client.getTransactionReceipt({
103-
hash: transactionHash
117+
txResponse = await publicClient.getTransactionReceipt({
118+
hash: transactionHash as Hex
104119
})
105120
} catch {
106121
// Do nothing

src/customActions/sendTransaction.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ export async function sendTransaction<
3333
const result = await wallet.sendTransaction(
3434
deepHexlify({
3535
to: to,
36-
value: value || "0x00",
37-
data: data || "0x00",
36+
value: value || '0x00',
37+
data: data || '0x00'
3838
})
3939
)
4040

src/customActions/signMessage.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ComethWallet } from '@cometh/connect-sdk'
2-
import { Account, Chain, Client, Hex, SignableMessage, Transport } from 'viem'
2+
import { Account, Hex, SignableMessage } from 'viem'
33
import { ErrorType } from 'viem/_types/errors/utils'
44
import { GetAccountParameter } from 'viem/_types/types/account'
55
import {
@@ -24,11 +24,7 @@ export type SignMessageErrorType =
2424
| ToHexErrorType
2525
| ErrorType
2626

27-
export async function signMessage<
28-
TChain extends Chain | undefined,
29-
TAccount extends Account | undefined
30-
>(
31-
client: Client<Transport, TChain, TAccount>,
27+
export async function signMessage<TAccount extends Account | undefined>(
3228
args: SignMessageWithConnectParameters<TAccount>
3329
): Promise<SignMessageReturnType> {
3430
const { message, wallet } = args

src/wagmi/connector.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export interface WagmiConfigConnectorParams {
2929
webAuthnOptions?: webAuthnOptions
3030
passKeyName?: string
3131
uiConfig?: UIConfig
32+
gasToken?: string
3233
baseUrl?: string
3334
rpcUrl?: string
3435
}
@@ -116,6 +117,7 @@ export function comethConnectConnector(
116117
passKeyName,
117118
baseUrl,
118119
uiConfig,
120+
gasToken,
119121
rpcUrl
120122
} = parameters
121123

@@ -135,6 +137,7 @@ export function comethConnectConnector(
135137
}),
136138
apiKey,
137139
uiConfig,
140+
gasToken,
138141
rpcUrl,
139142
baseUrl
140143
})

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -415,10 +415,10 @@
415415
preact "^10.16.0"
416416
sha.js "^2.4.11"
417417

418-
"@cometh/connect-sdk@^1.2.21":
419-
version "1.2.21"
420-
resolved "https://registry.yarnpkg.com/@cometh/connect-sdk/-/connect-sdk-1.2.21.tgz#86e1c119b14b08cf576a08004be4fdd5ebaa5d22"
421-
integrity sha512-abw8wEy7MjXIZ2Mcwv84wSeHajQe0aODI2Ir0J6haRp5/8IqFbU67AhKrB9rnwhhtfvYmWxgX/gRHKMXILJpwA==
418+
"@cometh/connect-sdk@^1.2.25":
419+
version "1.2.25"
420+
resolved "https://registry.yarnpkg.com/@cometh/connect-sdk/-/connect-sdk-1.2.25.tgz#9cbd07006fb77ff7126f436d5beeb160a3d9d287"
421+
integrity sha512-OsRtfMCyFksP0Di1ZfgnIT2pVKfyvR/e5WUfqqLNTQfB9S8yDIMN1OggqmZKTVXUAaZ7tEfkrKdWdZ1ltth3qw==
422422
dependencies:
423423
"@alembic/ui" "^1.5.4"
424424
"@babel/traverse" "^7.23.4"

0 commit comments

Comments
 (0)