Skip to content

Commit

Permalink
refactor(wallet): fixes any types usage (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
ygrishajev committed Apr 18, 2024
1 parent 7f11ac8 commit 433817c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 22 deletions.
1 change: 1 addition & 0 deletions src/certificates/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { createStarGateMessage } from "../pbclient/pbclient";
import { QueryCertificatesRequest, QueryCertificatesResponse } from "../protobuf/akash/cert/v1beta3/query";
import { CertificateFilter } from "../protobuf/akash/cert/v1beta1/cert";

// eslint-disable-next-line @typescript-eslint/no-var-requires
const JsonRPC = require("simple-jsonrpc-js");

import { toBase64 } from "pvutils";
Expand Down
37 changes: 17 additions & 20 deletions src/keplr/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { getAkashTypeRegistry } from "../stargate";
import { defaultRegistryTypes, SigningStargateClient } from "@cosmjs/stargate";
import { Registry } from "@cosmjs/proto-signing";
import { OfflineDirectSigner, OfflineSigner, Registry } from "@cosmjs/proto-signing";
import { AminoTypes } from "@cosmjs/stargate";
import { Certificate } from "../protobuf/akash/cert/v1beta2/cert";
import { MsgCreateCertificate } from "../protobuf/akash/cert/v1beta1/cert";

interface Chain {
id: string;
}

export function getChains() {
return {
Expand All @@ -15,45 +20,37 @@ export function getChains() {
};
}

export function getSigner(chain: any) {
return (window as any).getOfflineSignerAuto(chain.id);
export function getSigner(chain: Chain) {
return window.getOfflineSignerAuto(chain.id);
}

export async function get(chain: any, signer: any, endPoint: string) {
const customAminoTypes: any = new AminoTypes({
export async function get(chain: Chain, signer: OfflineSigner | OfflineDirectSigner, endPoint: string) {
const customAminoTypes = new AminoTypes({
"/akash.cert.v1beta2.MsgCreateCertificate": {
aminoType: "cert/cert-create-certificate",
toAmino: ({ owner, cert, pubkey }: any) => {
const buf: any = Certificate.encode(
toAmino: ({ cert, pubkey }: MsgCreateCertificate) => {
const buf = Certificate.encode(
Certificate.fromPartial({
owner,
cert,
pubkey
} as any)
})
).finish();
const encoded = Buffer.from(buf);
return encoded.toString("base64");
},
fromAmino: ({ owner, cert, pubkey }: any) => {
fromAmino: ({ cert, pubkey }: MsgCreateCertificate) => {
return Certificate.fromPartial({
owner,
cert,
pubkey
} as any);
});
}
}
} as any);
});

const myRegistry = new Registry([...defaultRegistryTypes, ...getAkashTypeRegistry()]);

return await SigningStargateClient.connectWithSigner(endPoint, signer, {
bip44: {
coinType: "118"
},
registry: myRegistry,
aminoTypes: customAminoTypes
} as any);
}
function bufferToHex(buffer: any) {
return [...new Uint8Array(buffer)].map(b => b.toString(16).padStart(2, "0")).join("");
});
}
4 changes: 3 additions & 1 deletion src/sdl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ export class SDL {

if (
units > 0 &&
Object.values(gpu.attributes?.vendor || {}).some(models => models?.some(model => model.interface && !GPU_SUPPORTED_INTERFACES.includes(model.interface)))
Object.values(gpu.attributes?.vendor || {}).some(models =>
models?.some(model => model.interface && !GPU_SUPPORTED_INTERFACES.includes(model.interface))
)
) {
throw new Error(`GPU interface must be one of the supported interfaces (${GPU_SUPPORTED_INTERFACES.join(",")}).`);
}
Expand Down
9 changes: 9 additions & 0 deletions src/types/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { OfflineDirectSigner, OfflineSigner } from "@cosmjs/proto-signing";

export {};

declare global {
interface Window {
getOfflineSignerAuto: (chainId: string) => Promise<OfflineSigner | OfflineDirectSigner>;
}
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@
"skipLibCheck": true /* Skip type checking of declaration files. */,
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
},
"include": ["./src"],
"include": ["./src/**/*"],
"exclude": ["./examples", "./tests"]
}

0 comments on commit 433817c

Please sign in to comment.