Skip to content

Commit

Permalink
refactor: Move relays data source to backend
Browse files Browse the repository at this point in the history
  • Loading branch information
originalix committed Nov 26, 2023
1 parent 8786679 commit 8bf4d64
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
23 changes: 7 additions & 16 deletions packages/kit-bg/src/providers/ProviderApiNostr.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { web3Errors } from '@onekeyfe/cross-inpage-provider-errors';
import { IInjectedProviderNames } from '@onekeyfe/cross-inpage-provider-types';

import type { NostrEvent } from '@onekeyhq/engine/src/vaults/utils/nostr/nostr';
import type {
INostrRelays,
NostrEvent,
} from '@onekeyhq/engine/src/vaults/utils/nostr/types';
import { getActiveWalletAccount } from '@onekeyhq/kit/src/hooks';
import {
ModalRoutes,
Expand Down Expand Up @@ -74,21 +77,9 @@ class ProviderApiNostr extends ProviderApiBase {
}

@providerApiMethod()
public async getRelays(): Promise<{
[url: string]: { read: boolean; write: boolean };
}> {
return Promise.resolve({
'wss://relay.relayable.org': { read: true, write: true },
'wss://relay.nostrassets.com': { read: true, write: true },
'wss://relay.damus.io': { read: true, write: true },
'wss://nostr1.tunnelsats.com': { read: true, write: true },
'wss://nostr-pub.wellorder.net': { read: true, write: true },
'wss://relay.nostr.info': { read: true, write: true },
'wss://nostr-relay.wlvs.space': { read: true, write: true },
'wss://nostr.bitcoiner.social': { read: true, write: true },
'wss://nostr-01.bolt.observer': { read: true, write: true },
'wss://relayer.fiatjaf.com': { read: true, write: true },
});
public async getRelays(): Promise<INostrRelays> {
const result = await this.backgroundApi.serviceNostr.getRelays();
return result;
}

@providerApiMethod()
Expand Down
15 changes: 14 additions & 1 deletion packages/kit-bg/src/services/ServiceNostr.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import axios from 'axios';
import ExpiryMap from 'expiry-map';

import type { ExportedSeedCredential } from '@onekeyhq/engine/src/dbs/base';
import type { NostrEvent } from '@onekeyhq/engine/src/vaults/utils/nostr/nostr';
import { getFiatEndpoint } from '@onekeyhq/engine/src/endpoint';
import {
Nostr,
validateEvent,
} from '@onekeyhq/engine/src/vaults/utils/nostr/nostr';
import type {
INostrRelays,
NostrEvent,
} from '@onekeyhq/engine/src/vaults/utils/nostr/types';
import { getTimeDurationMs } from '@onekeyhq/kit/src/utils/helper';
import {
backgroundClass,
Expand Down Expand Up @@ -155,4 +160,12 @@ export default class ServiceNostr extends ServiceBase {
data: signedHash,
};
}

@backgroundMethod()
async getRelays() {
const { data } = await axios.get<INostrRelays>(
`${getFiatEndpoint()}/nostr/getRelays`,
);
return data;
}
}

0 comments on commit 8bf4d64

Please sign in to comment.