Skip to content

Commit

Permalink
Merge pull request #25 from casper-ecosystem/George/Type-Fix
Browse files Browse the repository at this point in the history
Fix types and error handling for Signer methods
  • Loading branch information
George-cl authored Apr 15, 2021
2 parents 2ef49ce + 9294998 commit 3725c8b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
6 changes: 3 additions & 3 deletions src/@types/casperlabsSigner.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ interface CasperLabsHelper {
/**
* Returns connection status from Signer
*/
isConnected: () => Promise<boolean | undefined>;
isConnected: () => Promise<boolean>;
/**
* Attempt connection to Signer
*/
Expand All @@ -15,7 +15,7 @@ interface CasperLabsHelper {
*/
sign: (messageBase16: string, publicKeyBase64?: string) => Promise<string>;
// returns base64 encoded public key of user current selected account.
getSelectedPublicKeyBase64: () => Promise<string | undefined>;
getSelectedPublicKeyBase64: () => Promise<string>;
}

interface SignerTestingHelper {
Expand All @@ -30,7 +30,7 @@ interface SignerTestingHelper {
/**
* Check if there is an existing vault
*/
hasCreatedVault: () => Promise<boolean | undefined>;
hasCreatedVault: () => Promise<boolean>;
/**
* Reset existing vault (for testing) prevents complications
* and unlocks in preparation for creating an account
Expand Down
18 changes: 3 additions & 15 deletions src/lib/Signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* Check whether CasperLabs Signer extension is connected
*/
export const isConnected: () => Promise<boolean | undefined> = async () => {
export const isConnected: () => Promise<boolean> = async () => {
return await window.casperlabsHelper!.isConnected();
};

Expand All @@ -24,10 +24,7 @@ export const sendConnectionRequest: () => void = () => {
*
* @throws Error if haven't connected to CasperLabs Signer browser extension.
*/
export const getSelectedPublicKeyBase64: () => Promise<
string | undefined
> = () => {
throwIfNotConnected();
export const getSelectedPublicKeyBase64: () => Promise<string> = () => {
return window.casperlabsHelper!.getSelectedPublicKeyBase64();
};

Expand All @@ -44,7 +41,6 @@ export const sign: (
messageBase16: string,
publicKeyBase64?: string
) => Promise<string> = (messageBase16: string, publicKeyBase64?: string) => {
throwIfNotConnected();
return window.casperlabsHelper!.sign(messageBase16, publicKeyBase64);
};

Expand All @@ -56,7 +52,7 @@ export const forceDisconnect: () => void = () => {
return window.signerTestingHelper!.forceDisconnect();
};

export const hasCreatedVault: () => Promise<boolean | undefined> = () => {
export const hasCreatedVault: () => Promise<boolean> = () => {
return window.signerTestingHelper!.hasCreatedVault();
};

Expand Down Expand Up @@ -86,11 +82,3 @@ export const signTestDeploy: (msgId: number) => Promise<void> = (
) => {
return window.signerTestingHelper!.signTestDeploy(msgId);
};

const throwIfNotConnected = () => {
if (!isConnected()) {
throw new Error(
'No CasperLabs Signer browser plugin detected or it is not ready'
);
}
};

0 comments on commit 3725c8b

Please sign in to comment.