Skip to content
This repository was archived by the owner on Dec 23, 2024. It is now read-only.

Commit dd1a40b

Browse files
committed
fix: Fix protocol handling
1 parent 5a00d03 commit dd1a40b

File tree

2 files changed

+52
-36
lines changed

2 files changed

+52
-36
lines changed

lib/api/nostr-relays.dart

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import "package:http/http.dart" as http;
55
import 'package:locus/constants/apis.dart';
66
import 'package:locus/constants/values.dart';
77

8+
import '../widgets/RelaySelectSheet.dart';
9+
810
final RELAY_FETCHER_FUNCTIONS = [
911
NostrWatchAPI.getPublicNostrRelays,
1012
NostrBandAPI.getTrendingProfiles,
1113
NostrWatchAPI.getAllNostrRelays,
12-
() => Future.value(FALLBACK_RELAYS),
14+
() => Future.value(FALLBACK_RELAYS),
1315
];
1416

1517
// Tries each of the fallback relays until one works
@@ -73,40 +75,15 @@ class NostrBandAPI {
7375
List<dynamic>.from(jsonDecode(response.body)["profiles"])
7476
.map((e) => e["relays"])
7577
.expand((element) => element)
76-
.toSet());
78+
.toSet()
79+
.map((element) {
80+
final rawDomain = DOMAIN_REPLACE_REGEX.firstMatch(element);
81+
82+
if (rawDomain == null) {
83+
return null;
84+
}
85+
86+
return addProtocol(rawDomain.group(1)!);
87+
}).where((element) => element != null));
7788
}
7889
}
79-
80-
// Top 30 most used free relays
81-
const FALLBACK_RELAYS = [
82-
"relay.damus.io",
83-
"eden.nostr.land",
84-
"nos.lol",
85-
"relay.snort.social",
86-
"relay.current.fyi",
87-
"brb.io",
88-
"nostr.orangepill.dev",
89-
"nostr-pub.wellorder.net",
90-
"nostr.bitcoiner.social",
91-
"nostr.wine",
92-
"nostr.oxtr.dev",
93-
"relay.nostr.bg",
94-
"nostr.mom",
95-
"nostr.fmt.wiz.biz",
96-
"relay.nostr.band",
97-
"nostr-pub.semisol.dev",
98-
"nostr.milou.lol",
99-
"nostr.onsats.org",
100-
"relay.nostr.info",
101-
"puravida.nostr.land",
102-
"offchain.pub",
103-
"relay.orangepill.dev",
104-
"no.str.cr",
105-
"nostr.zebedee.cloud",
106-
"atlas.nostr.land",
107-
"nostr-relay.wlvs.space",
108-
"relay.nostrati.com",
109-
"relay.nostr.com.au",
110-
"relay.inosta.cc",
111-
"nostr.rocks",
112-
];

lib/constants/apis.dart

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,43 @@
1+
import 'package:locus/widgets/RelaySelectSheet.dart';
2+
13
const NOSTR_PUBLIC_RELAYS_LIST_URI = "https://api.nostr.watch/v1/public";
24
const NOSTR_ONLINE_RELAYS_LIST_URI = "https://api.nostr.watch/v1/online";
35
const NOSTR_TRENDING_PROFILES_URI =
46
"https://api.nostr.band/v0/trending/profiles";
7+
8+
// Top 30 most used free relays
9+
final FALLBACK_RELAYS = [
10+
"relay.damus.io",
11+
"eden.nostr.land",
12+
"nos.lol",
13+
"relay.snort.social",
14+
"relay.current.fyi",
15+
"brb.io",
16+
"nostr.orangepill.dev",
17+
"nostr-pub.wellorder.net",
18+
"nostr.bitcoiner.social",
19+
"nostr.wine",
20+
"nostr.oxtr.dev",
21+
"relay.nostr.bg",
22+
"nostr.mom",
23+
"nostr.fmt.wiz.biz",
24+
"relay.nostr.band",
25+
"nostr-pub.semisol.dev",
26+
"nostr.milou.lol",
27+
"nostr.onsats.org",
28+
"relay.nostr.info",
29+
"puravida.nostr.land",
30+
"offchain.pub",
31+
"relay.orangepill.dev",
32+
"no.str.cr",
33+
"nostr.zebedee.cloud",
34+
"atlas.nostr.land",
35+
"nostr-relay.wlvs.space",
36+
"relay.nostrati.com",
37+
"relay.nostr.com.au",
38+
"relay.inosta.cc",
39+
"nostr.rocks",
40+
].map(addProtocol).toList();
41+
42+
// Strip everything after the domain for regex
43+
final DOMAIN_REPLACE_REGEX = RegExp(r"(wss:\/\/[-\w.]+)(?:\/.*)?");

0 commit comments

Comments
 (0)