Skip to content

Commit

Permalink
feat: await for hackConnect
Browse files Browse the repository at this point in the history
  • Loading branch information
valpinkman committed Mar 21, 2024
1 parent f2f70da commit 321c5e7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/new-wolves-hope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/device-sdk-core": patch
---

use promise
6 changes: 4 additions & 2 deletions packages/core/src/api/DeviceSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ export class DeviceSdk {
}

// HACKATHON STUFF
hackConnectAndDiscover() {
this.container.get<HackathonService>(hackTypes.HackathonService).discover();
async hackConnectAndDiscover() {
await this.container
.get<HackathonService>(hackTypes.HackathonService)
.discover();
}

hackDisconnect() {
Expand Down
31 changes: 19 additions & 12 deletions packages/core/src/internal/hackathon/HackathonService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,25 @@ export class HackathonService {
this.connectedDevice.removeEventListener("inputreport", this.listener);
}

discover() {
return this.startDiscoveringUseCase.execute().subscribe({
next: (device) => {
this.discoveredDevice = device;
this.connect().catch((err) => console.log(err));
},
complete: () => {
this.stopDiscoveringUseCase.execute();
},
error: (error) => {
console.error(error);
},
async discover() {
return new Promise((res, rej) => {
this.startDiscoveringUseCase.execute().subscribe({
next: (device) => {
this.discoveredDevice = device;
this.connect()
.then(() => {
res(undefined);
})
.catch((err) => console.log(err));
},
complete: () => {
this.stopDiscoveringUseCase.execute();
},
error: (error) => {
rej(error);
console.error(error);
},
});
});
}

Expand Down

0 comments on commit 321c5e7

Please sign in to comment.