Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update snapRPC types and fix snapRequest #525

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/keystore/SnapKeystore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ export function SnapKeystore(
) as SnapKeystoreApiEntries) {
generatedMethods[method] = async (req?: SnapKeystoreApiRequestValues) => {
if (!rpc.req) {
return snapRPC(method, rpc, undefined, snapMeta, snapId)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return snapRPC(method, rpc, undefined, snapMeta, snapId) as any
}
return snapRPC(method, rpc, req, snapMeta, snapId)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return snapRPC(method, rpc, req, snapMeta, snapId) as any
}
}

Expand Down
9 changes: 5 additions & 4 deletions src/keystore/snapHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ export async function snapRPC<T extends SnapKeystoreApiMethods>(
throw new Error('Unexpected array response')
}

const decoder = rpc.res.decode as SnapKeystoreApiResponseDecoders[T]
return decoder(b64Decode(responseString))
return rpc.res.decode(b64Decode(responseString)) as ReturnType<
SnapKeystoreApiResponseDecoders[T]
>
}

export async function snapRequest(
Expand All @@ -78,11 +79,11 @@ export async function snapRequest(
},
})

if (!response || !response.res) {
if (!response || typeof response !== 'object') {
throw new Error('No response value')
}

return response.res
return (response as SnapResponse).res
}

export type Snap = {
Expand Down
Loading