Skip to content

Commit

Permalink
Merge pull request #124 from docknetwork/fix/background-notificationss
Browse files Browse the repository at this point in the history
fixing issues with background notifications
  • Loading branch information
maycon-mello authored Jun 20, 2023
2 parents d9b679d + 60490f5 commit a328035
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions packages/wasm/lib/services/relay-service/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,29 @@ import {
serviceName,
validation,
} from './configs';

import {dockService} from '../dock/service';
import {RelayService as relayServiceClient} from '@docknetwork/wallet-sdk-relay-service/lib';

export function waitFor(condition, timeout) {
return new Promise((resolve, reject) => {
const interval = setInterval(async () => {
if (await Promise.resolve(condition())) {
clearInterval(interval);
resolve(true);
}
}, 400);

setTimeout(() => {
clearInterval(interval);
reject(new Error('Timed out'));
}, timeout);
});
}

function ensureDockNetwork() {
return waitFor(() => dockService.isApiConnected(), 8000);
}

/**
* RelayService
*/
Expand All @@ -24,18 +44,27 @@ export class RelayService {
this.name = serviceName;
}

sendMessage(params: SendMessageParams) {
async sendMessage(params: SendMessageParams) {
validation.sendMessage(params);

await ensureDockNetwork();

return relayServiceClient.sendMessage(params);
}

resolveDidcommMessage(params: ResolveDidcommMessageParams) {
async resolveDidcommMessage(params: ResolveDidcommMessageParams) {
validation.resolveDidcommMessage(params);

await ensureDockNetwork();

return relayServiceClient.resolveDidcommMessage(params);
}

getMessages(params: GetMessagesParams) {
async getMessages(params: GetMessagesParams) {
validation.getMessages(params);

await ensureDockNetwork();

return relayServiceClient.getMessages(params);
}

Expand Down

0 comments on commit a328035

Please sign in to comment.