11import type { AminoSignResponse } from "@cosmjs/amino" ;
22import type { AccountData , Algo , DirectSignResponse } from "@cosmjs/proto-signing" ;
33import type { Keplr } from "@keplr-wallet/types" ;
4+ import { WalletConnectModal } from "@walletconnect/modal" ;
45import { SignClient } from "@walletconnect/sign-client" ;
56import type { ISignClient , SignClientTypes } from "@walletconnect/types" ;
67import { getSdkError } from "@walletconnect/utils" ;
7- import Long from "long " ;
8+ import type { SignDoc } from "cosmjs-types/cosmos/tx/v1beta1/tx " ;
89
910import { useGrazInternalStore , useGrazSessionStore } from "../../../store" ;
10- import { Key , type SignAminoParams , type SignDirectParams , type Wallet , WalletType } from "../../../types/wallet" ;
11+ import type { Key } from "../../../types/wallet" ;
12+ import { type SignAminoParams , type SignDirectParams , type Wallet , WalletType } from "../../../types/wallet" ;
1113import { isAndroid , isIos , isMobile } from "../../../utils/os" ;
1214import { promiseWithTimeout } from "../../../utils/timeout" ;
1315import type { GetWalletConnectParams , WalletConnectSignDirectResponse } from "./types" ;
14- import { WalletConnectModal } from "@walletconnect/modal" ;
1516
1617export const getWalletConnect = ( params ?: GetWalletConnectParams ) : Wallet => {
1718 if ( ! useGrazInternalStore . getState ( ) . walletConnect ?. options ?. projectId ?. trim ( ) ) {
@@ -205,6 +206,7 @@ export const getWalletConnect = (params?: GetWalletConnectParams): Wallet => {
205206 // "f896cbca30cd6dc414712d3d6fcc2f8f7d35d5bd30e3b1fc5d60cf6c8926f98f",
206207 // ],
207208 } ) ;
209+
208210 const lastSession = checkSession ( chainId ) ;
209211 if ( ! lastSession ) {
210212 const { uri, approval } = await promiseWithTimeout (
@@ -276,7 +278,8 @@ export const getWalletConnect = (params?: GetWalletConnectParams): Wallet => {
276278 await approving ( signal ) ;
277279 } catch ( error ) {
278280 walletConnectModal . closeModal ( ) ;
279- if ( ! ( error as Error ) . message . toLowerCase ( ) . includes ( "no matching key" ) ) return Promise . reject ( error ) ;
281+ if ( ! ( error as Error ) . message . toLowerCase ( ) . includes ( "no matching key" ) )
282+ return Promise . reject ( new Error ( error as string ) ) ;
280283 }
281284 if ( ! params ) {
282285 walletConnectModal . closeModal ( ) ;
@@ -288,7 +291,7 @@ export const getWalletConnect = (params?: GetWalletConnectParams): Wallet => {
288291 ( async ( ) => {
289292 const resultAcccounts = Object . fromEntries (
290293 await Promise . all (
291- ( activeChainIds || chainId ) ? .map ( async ( c ) : Promise < [ string , Key ] > => [ c , await getKey ( c ) ] ) ,
294+ ( activeChainIds || chainId ) . map ( async ( c ) : Promise < [ string , Key ] > => [ c , await getKey ( c ) ] ) ,
292295 ) ,
293296 ) ;
294297 useGrazSessionStore . setState ( {
@@ -356,8 +359,8 @@ export const getWalletConnect = (params?: GetWalletConnectParams): Wallet => {
356359 signDoc : {
357360 chainId : signDoc . chainId ,
358361 accountNumber : signDoc . accountNumber ?. toString ( ) ,
359- bodyBytes : signDoc . bodyBytes ? Buffer . from ( signDoc . bodyBytes ) . toString ( encoding ) : null ,
360- authInfoBytes : signDoc . authInfoBytes ? Buffer . from ( signDoc . authInfoBytes ) . toString ( encoding ) : null ,
362+ bodyBytes : Buffer . from ( signDoc . bodyBytes ) . toString ( encoding ) || null ,
363+ authInfoBytes : Buffer . from ( signDoc . authInfoBytes ) . toString ( encoding ) || null ,
361364 } ,
362365 } ,
363366 } ,
@@ -370,12 +373,10 @@ export const getWalletConnect = (params?: GetWalletConnectParams): Wallet => {
370373 const { signature, signed } = await wcSignDirect ( chainId , signer , signDoc ) ;
371374 return {
372375 signed : {
373- chainId : signed . chainId ?? "" ,
374- accountNumber : signed . accountNumber ? Long . fromString ( signed . accountNumber ) : new Long ( 0 ) ,
375- authInfoBytes : signed . authInfoBytes
376- ? new Uint8Array ( Buffer . from ( signed . authInfoBytes , encoding ) )
377- : new Uint8Array ( [ ] ) ,
378- bodyBytes : signed . bodyBytes ? new Uint8Array ( Buffer . from ( signed . bodyBytes , encoding ) ) : new Uint8Array ( [ ] ) ,
376+ chainId : signed . chainId ,
377+ accountNumber : BigInt ( signed . accountNumber ) ,
378+ authInfoBytes : new Uint8Array ( Buffer . from ( signed . authInfoBytes , encoding ) ) ,
379+ bodyBytes : new Uint8Array ( Buffer . from ( signed . bodyBytes , encoding ) ) ,
379380 } ,
380381 signature,
381382 } ;
@@ -416,8 +417,7 @@ export const getWalletConnect = (params?: GetWalletConnectParams): Wallet => {
416417 const getOfflineSignerDirect = ( chainId : string ) => {
417418 return {
418419 getAccounts : async ( ) => [ await getAccount ( chainId ) ] ,
419- signDirect : ( signerAddress : string , signDoc : SignDirectParams [ "2" ] ) =>
420- signDirect ( chainId , signerAddress , signDoc ) ,
420+ signDirect : ( signerAddress : string , signDoc : SignDoc ) => signDirect ( chainId , signerAddress , signDoc ) ,
421421 } ;
422422 } ;
423423
0 commit comments