Skip to content

Commit f658627

Browse files
feat: update wallet types
1 parent ee99451 commit f658627

File tree

8 files changed

+48
-26
lines changed

8 files changed

+48
-26
lines changed

packages/graz/src/actions/wallet/cosmostation.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ export const getCosmostation = (): Wallet => {
3535
const setDefaultOptions = (options: KeplrIntereactionOptions) => {
3636
cosmostation.defaultOptions = options;
3737
};
38+
// TODO: CHECK IF THIS IS THE CORRECT WAY TO CAST
3839
const res = Object.assign(cosmostation, {
3940
subscription,
4041
setDefaultOptions,
41-
});
42+
}) as unknown as Wallet;
4243
return res;
4344
}
4445

packages/graz/src/actions/wallet/initia.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export const getInitia = (): Wallet => {
8080
pubKey: account.pubkey,
8181
bech32Address: account.address,
8282
address: rawAddress,
83+
ethereumHexAddress: "",
8384
isNanoLedger: false,
8485
isKeystone: false,
8586
};

packages/graz/src/actions/wallet/keplr.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@ export const getKeplr = (): Wallet => {
3434
const setDefaultOptions = (options: KeplrIntereactionOptions) => {
3535
keplr.defaultOptions = options;
3636
};
37+
38+
// TODO: CHECK IF THIS IS THE CORRECT WAY TO CAST
3739
const res = Object.assign(keplr, {
3840
subscription,
3941
setDefaultOptions,
40-
});
42+
}) as unknown as Wallet;
4143

4244
return res;
4345
}

packages/graz/src/actions/wallet/leap.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,13 @@ export const getLeap = (): Wallet => {
3434
const setDefaultOptions = (options: KeplrIntereactionOptions) => {
3535
leap.defaultOptions = options;
3636
};
37+
38+
// TODO: CHECK IF THIS IS THE CORRECT WAY TO CAST
3739
const res = Object.assign(leap, {
3840
subscription,
3941
setDefaultOptions,
40-
});
42+
}) as unknown as Wallet;
43+
4144
return res;
4245
}
4346

packages/graz/src/actions/wallet/okx.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@ export const getOkx = (): Wallet => {
3434
const setDefaultOptions = (options: KeplrIntereactionOptions) => {
3535
okxWallet.defaultOptions = options;
3636
};
37+
38+
// TODO: CHECK IF THIS IS THE CORRECT WAY TO CAST
3739
const res = Object.assign(okxWallet, {
3840
subscription,
3941
setDefaultOptions,
40-
});
42+
}) as unknown as Wallet;
4143
return res;
4244
}
4345

packages/graz/src/actions/wallet/vectis.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import type { AminoSignResponse } from "@cosmjs/amino";
1+
import type { AminoSignResponse, OfflineAminoSigner } from "@cosmjs/amino";
22
import { fromBech32 } from "@cosmjs/encoding";
3-
import type { DirectSignResponse } from "@cosmjs/proto-signing";
3+
import type { DirectSignResponse, OfflineDirectSigner } from "@cosmjs/proto-signing";
4+
import type { ChainInfo } from "@vectis/extension-client";
45
import Long from "long";
56

67
import { useGrazInternalStore } from "../../store";
78
import type { Key, SignAminoParams, SignDirectParams, Wallet } from "../../types/wallet";
89
import { clearSession } from ".";
9-
import { ChainInfo } from "@vectis/extension-client";
1010

1111
/**
1212
* Function to return {@link Wallet} object and throws and error if it does not exist on `window`.
@@ -48,7 +48,7 @@ export const getVectis = (): Wallet => {
4848
rpcUrl: chainInfo.rpc,
4949
restUrl: chainInfo.rest,
5050
prettyName: chainInfo.chainName.replace(" ", ""),
51-
bech32Prefix: chainInfo.bech32Config?.bech32PrefixAccAddr,
51+
bech32Prefix: chainInfo.bech32Config.bech32PrefixAccAddr,
5252
currencies: chainInfo.currencies,
5353
feeCurrencies: chainInfo.feeCurrencies,
5454
chainId: chainInfo.chainId,
@@ -75,23 +75,35 @@ export const getVectis = (): Wallet => {
7575

7676
const signDirect = async (...args: SignDirectParams): Promise<DirectSignResponse> => {
7777
const { 1: signer, 2: signDoc } = args;
78-
return vectis.signDirect(signer, {
78+
const response = await vectis.signDirect(signer, {
7979
bodyBytes: signDoc.bodyBytes || Uint8Array.from([]),
8080
authInfoBytes: signDoc.authInfoBytes || Uint8Array.from([]),
8181
accountNumber: Long.fromString(signDoc.accountNumber?.toString() || "", false),
8282
chainId: signDoc.chainId || "",
8383
});
84+
85+
return {
86+
...response,
87+
signed: {
88+
...response.signed,
89+
accountNumber: BigInt(signDoc.accountNumber ?? 0),
90+
},
91+
};
8492
};
8593

8694
const signAmino = async (...args: SignAminoParams): Promise<AminoSignResponse> => {
8795
const { 1: signer, 2: signDoc } = args;
8896
return vectis.signAmino(signer, signDoc);
8997
};
9098

99+
const getOfflineSignerAuto = (chainId: string): Promise<OfflineAminoSigner | OfflineDirectSigner> => {
100+
return vectis.getOfflineSignerAuto(chainId) as unknown as Promise<OfflineAminoSigner | OfflineDirectSigner>;
101+
};
102+
91103
return {
92104
enable: (chainId: string | string[]) => vectis.enable(chainId),
93105
getOfflineSigner: (chainId: string) => vectis.getOfflineSigner(chainId),
94-
getOfflineSignerAuto: (chainId: string) => vectis.getOfflineSignerAuto(chainId),
106+
getOfflineSignerAuto,
95107
getKey,
96108
subscription,
97109
getOfflineSignerOnlyAmino,

packages/graz/src/actions/wallet/wallet-connect/index.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import type { AminoSignResponse } from "@cosmjs/amino";
22
import type { AccountData, Algo, DirectSignResponse } from "@cosmjs/proto-signing";
33
import type { Keplr } from "@keplr-wallet/types";
4+
import { WalletConnectModal } from "@walletconnect/modal";
45
import { SignClient } from "@walletconnect/sign-client";
56
import type { ISignClient, SignClientTypes } from "@walletconnect/types";
67
import { getSdkError } from "@walletconnect/utils";
7-
import Long from "long";
8+
import type { SignDoc } from "cosmjs-types/cosmos/tx/v1beta1/tx";
89

910
import { 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";
1113
import { isAndroid, isIos, isMobile } from "../../../utils/os";
1214
import { promiseWithTimeout } from "../../../utils/timeout";
1315
import type { GetWalletConnectParams, WalletConnectSignDirectResponse } from "./types";
14-
import { WalletConnectModal } from "@walletconnect/modal";
1516

1617
export 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

packages/graz/src/actions/wallet/xdefi.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ export const getXDefi = (): Wallet => {
2929
window.removeEventListener("keplr_keystorechange", listener);
3030
};
3131
};
32+
// TODO: CHECK IF THIS IS THE CORRECT WAY TO CAST
3233
const res = Object.assign(xdefi, {
3334
subscription,
34-
});
35+
}) as unknown as Wallet;
3536

3637
return res;
3738
}

0 commit comments

Comments
 (0)