Skip to content

Commit

Permalink
Clean up error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
olistic committed Jul 6, 2023
1 parent aa5f02b commit eb2b707
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/address/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const getAddress = async (options: GetAddressOptions) => {
const { getProvider = getDefaultProvider } = options;
const provider = await getProvider();
if (!provider) {
throw new Error('No Bitcoin Wallet installed');
throw new Error('No Bitcoin wallet installed');
}

const { purposes } = options.payload;
Expand Down
2 changes: 1 addition & 1 deletion src/call/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const callWalletPopup = async (options: CallWalletOptions) => {
const { getProvider = getDefaultProvider } = options;
const provider = await getProvider();
if (!provider) {
throw new Error('No Bitcoin Wallet installed');
throw new Error('No Bitcoin wallet installed');
}

const { method } = options.payload;
Expand Down
8 changes: 4 additions & 4 deletions src/signatures/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ export const signMessage = async (options: SignMessageOptions) => {
const { getProvider = getDefaultProvider } = options;
const provider = await getProvider();
if (!provider) {
throw new Error('No Bitcoin Wallet installed');
throw new Error('No Bitcoin wallet installed');
}

const { address, message } = options.payload;
if (!address) {
throw new Error('An Address is required to sign a message');
throw new Error('An address is required to sign a message');
}
if (!message) {
throw new Error('you need to provide a message to be signed');
throw new Error('A message to be signed is required');
}

try {
const request = createUnsecuredToken(options.payload as unknown as Json);
const response = await provider.signMessage(request);
options.onFinish?.(response);
} catch (error) {
console.error('[Connect] Error during Signing request', error);
console.error('[Connect] Error during sign message request', error);
options.onCancel?.();
}
};
Expand Down
8 changes: 4 additions & 4 deletions src/transactions/sendBtcTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,23 @@ export const sendBtcTransaction = async (options: SendBtcTransactionOptions) =>
const { getProvider = getDefaultProvider } = options;
const provider = await getProvider();
if (!provider) {
throw new Error('No Bitcoin Wallet installed');
throw new Error('No Bitcoin wallet installed');
}

const { amountSats, recipientAddress } = options.payload;
if (!amountSats) {
throw new Error('a value for amount to be transferred is required');
throw new Error('An amount to be transferred is required');
}
if (!recipientAddress) {
throw new Error('the recipient address is required');
throw new Error('A recipient address is required');
}

try {
const request = createUnsecuredToken(options.payload as unknown as Json);
const addressResponse = await provider.sendBtcTransaction(request);
options.onFinish?.(addressResponse);
} catch (error) {
console.error('[Connect] Error during send btc request', error);
console.error('[Connect] Error during send transaction request', error);
options.onCancel?.();
}
};
8 changes: 4 additions & 4 deletions src/transactions/signTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,23 @@ export const signTransaction = async (options: SignTransactionOptions) => {
const { getProvider = getDefaultProvider } = options;
const provider = await getProvider();
if (!provider) {
throw new Error('No Bitcoin Wallet installed');
throw new Error('No Bitcoin wallet installed');
}

const { psbtBase64, inputsToSign } = options.payload;
if (!psbtBase64) {
throw new Error('a value for psbtBase64 representing the tx hash is required');
throw new Error('A value for psbtBase64 representing the tx hash is required');
}
if (!inputsToSign) {
throw new Error('an array specifying the inputs to be signed by the wallet is required');
throw new Error('An array specifying the inputs to be signed by the wallet is required');
}

try {
const request = createUnsecuredToken(options.payload as unknown as Json);
const addressResponse = await provider.signTransaction(request);
options.onFinish?.(addressResponse);
} catch (error) {
console.error('[Connect] Error during signPsbt request', error);
console.error('[Connect] Error during sign transaction request', error);
options.onCancel?.();
}
};

0 comments on commit eb2b707

Please sign in to comment.