Skip to content

Commit

Permalink
fix: Fix protocol handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Myzel394 committed Aug 17, 2023
1 parent 5a00d03 commit dd1a40b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 36 deletions.
49 changes: 13 additions & 36 deletions lib/api/nostr-relays.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import "package:http/http.dart" as http;
import 'package:locus/constants/apis.dart';
import 'package:locus/constants/values.dart';

import '../widgets/RelaySelectSheet.dart';

final RELAY_FETCHER_FUNCTIONS = [
NostrWatchAPI.getPublicNostrRelays,
NostrBandAPI.getTrendingProfiles,
NostrWatchAPI.getAllNostrRelays,
() => Future.value(FALLBACK_RELAYS),
() => Future.value(FALLBACK_RELAYS),
];

// Tries each of the fallback relays until one works
Expand Down Expand Up @@ -73,40 +75,15 @@ class NostrBandAPI {
List<dynamic>.from(jsonDecode(response.body)["profiles"])
.map((e) => e["relays"])
.expand((element) => element)
.toSet());
.toSet()
.map((element) {
final rawDomain = DOMAIN_REPLACE_REGEX.firstMatch(element);

if (rawDomain == null) {
return null;
}

return addProtocol(rawDomain.group(1)!);
}).where((element) => element != null));
}
}

// Top 30 most used free relays
const FALLBACK_RELAYS = [
"relay.damus.io",
"eden.nostr.land",
"nos.lol",
"relay.snort.social",
"relay.current.fyi",
"brb.io",
"nostr.orangepill.dev",
"nostr-pub.wellorder.net",
"nostr.bitcoiner.social",
"nostr.wine",
"nostr.oxtr.dev",
"relay.nostr.bg",
"nostr.mom",
"nostr.fmt.wiz.biz",
"relay.nostr.band",
"nostr-pub.semisol.dev",
"nostr.milou.lol",
"nostr.onsats.org",
"relay.nostr.info",
"puravida.nostr.land",
"offchain.pub",
"relay.orangepill.dev",
"no.str.cr",
"nostr.zebedee.cloud",
"atlas.nostr.land",
"nostr-relay.wlvs.space",
"relay.nostrati.com",
"relay.nostr.com.au",
"relay.inosta.cc",
"nostr.rocks",
];
39 changes: 39 additions & 0 deletions lib/constants/apis.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,43 @@
import 'package:locus/widgets/RelaySelectSheet.dart';

const NOSTR_PUBLIC_RELAYS_LIST_URI = "https://api.nostr.watch/v1/public";
const NOSTR_ONLINE_RELAYS_LIST_URI = "https://api.nostr.watch/v1/online";
const NOSTR_TRENDING_PROFILES_URI =
"https://api.nostr.band/v0/trending/profiles";

// Top 30 most used free relays
final FALLBACK_RELAYS = [
"relay.damus.io",
"eden.nostr.land",
"nos.lol",
"relay.snort.social",
"relay.current.fyi",
"brb.io",
"nostr.orangepill.dev",
"nostr-pub.wellorder.net",
"nostr.bitcoiner.social",
"nostr.wine",
"nostr.oxtr.dev",
"relay.nostr.bg",
"nostr.mom",
"nostr.fmt.wiz.biz",
"relay.nostr.band",
"nostr-pub.semisol.dev",
"nostr.milou.lol",
"nostr.onsats.org",
"relay.nostr.info",
"puravida.nostr.land",
"offchain.pub",
"relay.orangepill.dev",
"no.str.cr",
"nostr.zebedee.cloud",
"atlas.nostr.land",
"nostr-relay.wlvs.space",
"relay.nostrati.com",
"relay.nostr.com.au",
"relay.inosta.cc",
"nostr.rocks",
].map(addProtocol).toList();

// Strip everything after the domain for regex
final DOMAIN_REPLACE_REGEX = RegExp(r"(wss:\/\/[-\w.]+)(?:\/.*)?");

0 comments on commit dd1a40b

Please sign in to comment.