This repository has been archived by the owner on Jan 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/BitcoinDevShop/pln
- Loading branch information
Showing
18 changed files
with
529 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:shared_preferences/shared_preferences.dart'; | ||
|
||
// ignore: constant_identifier_names | ||
const String PLN_GRPC_ENDPOINT = "PLN_GRPC_ENDPOINT"; | ||
|
||
class PrefsStateNotifier extends StateNotifier<String?> { | ||
PrefsStateNotifier(this.prefs) | ||
: super(prefs.get(PLN_GRPC_ENDPOINT) as String?); | ||
|
||
// String _federationCode; | ||
SharedPreferences prefs; | ||
|
||
/// Updates the value asynchronously. | ||
Future<void> update(String? value) async { | ||
if (value != null) { | ||
await prefs.setString(PLN_GRPC_ENDPOINT, value); | ||
} else { | ||
await prefs.remove(PLN_GRPC_ENDPOINT); | ||
} | ||
super.state = value; | ||
} | ||
|
||
/// Do not use the setter for state. | ||
/// Instead, use `await update(value).` | ||
@override | ||
set state(String? value) { | ||
assert(false, | ||
"Don't use the setter for state. Instead use `await update(value)`."); | ||
Future(() async { | ||
await update(value); | ||
}); | ||
} | ||
} | ||
|
||
StateNotifierProvider<PrefsStateNotifier, String?> createPrefProvider({ | ||
required SharedPreferences Function(Ref) prefs, | ||
}) { | ||
return StateNotifierProvider<PrefsStateNotifier, String?>( | ||
(ref) => PrefsStateNotifier(prefs(ref))); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,42 @@ | ||
import 'package:flutter/foundation.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:grpc/grpc.dart'; | ||
import 'package:pln/generated/pln.pbgrpc.dart'; | ||
import 'package:pln/main.dart'; | ||
|
||
final _channel = ClientChannel( | ||
'localhost', | ||
port: 5401, | ||
options: ChannelOptions( | ||
credentials: const ChannelCredentials.insecure(), | ||
codecRegistry: CodecRegistry(codecs: const [GzipCodec(), IdentityCodec()]), | ||
), | ||
); | ||
final plnClientProvider = | ||
StateNotifierProvider<PlnClient, ManagerClient?>((ref) { | ||
return PlnClient(ref); | ||
}); | ||
|
||
final plnClient = ManagerClient(_channel); | ||
class PlnClient extends StateNotifier<ManagerClient?> { | ||
PlnClient(this.ref) : super(null); | ||
|
||
final Ref ref; | ||
|
||
Future<void> restartClient() async { | ||
debugPrint("restarting grpc client"); | ||
|
||
try { | ||
final prefs = ref.read(prefProvider); | ||
|
||
final uri = Uri.parse(prefs ?? "http://localhost:5401"); | ||
|
||
// TODO is this all I need from the URI? | ||
final channel = ClientChannel(uri.host + uri.path, | ||
port: uri.port, | ||
options: ChannelOptions( | ||
credentials: const ChannelCredentials.insecure(), | ||
codecRegistry: | ||
CodecRegistry(codecs: const [GzipCodec(), IdentityCodec()]), | ||
)); | ||
state = ManagerClient(channel); | ||
} catch (e) { | ||
throw ("couldn't connect"); | ||
} | ||
} | ||
|
||
ManagerClient? get() { | ||
return state; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.