Skip to content

Commit

Permalink
fix: promise handling in authenticate
Browse files Browse the repository at this point in the history
  • Loading branch information
hstove committed Mar 17, 2021
1 parent 7b40c79 commit 1075ee2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
version:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, 'chore(release)')"
needs: [integration_tests, code_checks]
needs: [code_checks]
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down
11 changes: 6 additions & 5 deletions packages/connect/src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,19 @@ export const authenticate = (authOptions: AuthOptions) => {
}
);

try {
void provider.authenticationRequest(authRequest).then(async authResponse => {
void provider
.authenticationRequest(authRequest)
.then(async authResponse => {
await userSession.handlePendingSignIn(authResponse);
const success = onFinish || finished;
success?.({
authResponse,
userSession,
});
})
.catch(error => {
onCancel?.(error);
});
} catch (error) {
onCancel?.(error);
}
};

export const getUserData = async (userSession?: UserSession) => {
Expand Down
23 changes: 14 additions & 9 deletions packages/connect/src/transactions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,21 @@ const openTransactionPopup = ({ token, options }: TransactionPopup) => {
if (!provider) {
throw new Error('Stacks Wallet not installed.');
}
void provider.transactionRequest(token).then(data => {
const finishedCallback = options.finished || options.onFinish;
const { txRaw } = data;
const txBuffer = Buffer.from(txRaw.replace(/^0x/, ''), 'hex');
const stacksTransaction = deserializeTransaction(new BufferReader(txBuffer));
finishedCallback?.({
...data,
stacksTransaction,
void provider
.transactionRequest(token)
.then(data => {
const finishedCallback = options.finished || options.onFinish;
const { txRaw } = data;
const txBuffer = Buffer.from(txRaw.replace(/^0x/, ''), 'hex');
const stacksTransaction = deserializeTransaction(new BufferReader(txBuffer));
finishedCallback?.({
...data,
stacksTransaction,
});
})
.catch(error => {
console.error('[Connect] Error during transaction request', error);
});
});

if (true) return;
};
Expand Down

0 comments on commit 1075ee2

Please sign in to comment.