Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Networks added #215

Merged
merged 5 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions lib/core/crypto/dart_esr/src/signing_request_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -804,36 +804,36 @@ extension HyphaSigningRequestManager on SigningRequestManager {
/// Convert the ESR standard's "chain_id" to our Network
/// Both signify a unique identifier for a chain
/// But we support fewer chains than ESR does.
/// Networks maps to remote config which contains the server node URLs we need
/// Network maps to remote config which contains the server node URLs we need
/// to use in order to access supported chains.
/// Returns: Network
/// throws: unsupported network when the chainID can't be parsed.
///
static Networks resolveNetwork(List<dynamic> chainId) {
static Network resolveNetwork(List<dynamic> chainId) {
if (chainId[0] == 'chain_alias') {
// chain_alias officially only supports EOS mainnet, and Telos mainnet, as 1, and 2.
if (chainId[1] == 1) {
return Networks.eos;
return Network.eos;
} else if (chainId[1] == 2) {
return Networks.telos;
return Network.telos;
} else {
throw 'unsupported network alias ${chainId[1]}';
}
} else if (chainId[0] == 'chain_id') {
final ChainName name = SigningRequestUtils.idToName(chainId[1]);
switch (name) {
case ChainName.EOS:
return Networks.eos;
return Network.eos;
case ChainName.EOS_JUNGLE4:
return Networks.eosTestnet;
return Network.eosTestnet;
case ChainName.TELOS:
return Networks.telos;
return Network.telos;
case ChainName.TELOS_TESTNET:
return Networks.telosTestnet;
return Network.telosTestnet;
default:
throw 'unsupported network ${name.name}';
}
}
return Networks.eos;
return Network.eos;
}
}
6 changes: 3 additions & 3 deletions lib/core/crypto/seeds_esr/eos_transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:hypha_wallet/core/crypto/seeds_esr/eos_action.dart';
import 'package:hypha_wallet/core/network/api/services/remote_config_service.dart';

class EOSTransaction extends Equatable {
final Networks network;
final Network network;
final List<EOSAction> actions;
bool get isValid => actions.isNotEmpty;

Expand All @@ -16,7 +16,7 @@ class EOSTransaction extends Equatable {
@override
List<Object?> get props => [actions];

factory EOSTransaction.fromESRActionsList(List<esr.ESRAction> esrActions, Networks network) {
factory EOSTransaction.fromESRActionsList(List<esr.ESRAction> esrActions, Network network) {
final List<EOSAction> eosActions =
esrActions.map((e) => EOSAction.fromESRAction(e)).where((item) => item.isValid).toList();
return EOSTransaction(eosActions, network);
Expand All @@ -27,7 +27,7 @@ class EOSTransaction extends Equatable {
required String actionName,
required Map<String, dynamic> data,
List<eos.Authorization?>? authorization,
required Networks network,
required Network network,
}) =>
EOSTransaction([
EOSAction()
Expand Down
4 changes: 2 additions & 2 deletions lib/core/crypto/seeds_esr/seeds_esr.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class SeedsESR {
}

Result<ScanQrCodeResultData> processResolvedRequest() {
Networks network;
Network network;
try {
network = _resolveNetwork();
} catch (error) {
Expand All @@ -40,7 +40,7 @@ class SeedsESR {
}

/// Map ChainName or actual chain ID to our supported Network list
Networks _resolveNetwork() {
Network _resolveNetwork() {
final List<dynamic> chainId = manager.signingRequest.chainId;
return HyphaSigningRequestManager.resolveNetwork(chainId);
}
Expand Down
1 change: 1 addition & 0 deletions lib/core/di/bloc_module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,6 @@ void _registerBlocsModule() {

_registerFactory(() => SearchUserBloc(
_getIt<SearchForMemberUseCase>(),
_getIt<AuthRepository>(),
));
}
15 changes: 1 addition & 14 deletions lib/core/network/api/aws_amplify/amplify_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import 'package:hypha_wallet/core/network/api/aws_amplify/aws_authenticated_requ
import 'package:hypha_wallet/core/network/api/eos_service.dart';
import 'package:hypha_wallet/core/network/api/services/remote_config_service.dart';
import 'package:hypha_wallet/core/network/networking_manager.dart';
import 'package:hypha_wallet/ui/profile/interactor/profile_data.dart';

String getRandomString(int len) {
final random = Random.secure();
Expand Down Expand Up @@ -148,7 +147,7 @@ class AmplifyService {

// handle CUSTOM_CHALLENGE challenge
final loginCode = e.challengeParameters['loginCode'];
await eosService.loginWithCode(accountName: accountName, loginCode: loginCode, network: Networks.telos);
await eosService.loginWithCode(accountName: accountName, loginCode: loginCode, network: Network.telos);
print('return challenge $loginCode');
n13 marked this conversation as resolved.
Show resolved Hide resolved
session = await cognitoUser!.sendCustomChallengeAnswer(loginCode);

Expand All @@ -168,18 +167,6 @@ class AmplifyService {
return true;
}

Future<ProfileData> getProfile() async {
final result = await _request(
path: 'get-profile',
body: {
'originAppId': remoteConfigService.pppOriginAppId,
},
);
final Map<String, dynamic> data = result['profile'];
final ProfileData profile = ProfileData.fromPPPDataJson(data);
return profile;
}

///
/// register method is used to modify any user attributes such as name, bio, etc
///
Expand Down
10 changes: 5 additions & 5 deletions lib/core/network/api/eos_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class EOSService {

EOSService(this.secureStorageService, this.remoteConfigService);

EOSClient getEosClientForNetwork(Networks network, {List<String> privateKeys = const []}) {
EOSClient getEosClientForNetwork(Network network, {List<String> privateKeys = const []}) {
return EOSClient(
baseUrl: remoteConfigService.pushTransactionNodeUrl(network: network),
privateKeys: privateKeys,
Expand All @@ -26,7 +26,7 @@ class EOSService {
Future<Result<dynamic>> loginWithCode({
required String accountName,
required String loginCode,
required Networks network,
required Network network,
}) async {
final contractName = remoteConfigService.loginContract(network: network);
final actionName = remoteConfigService.loginAction(network: network);
Expand All @@ -52,7 +52,7 @@ class EOSService {
required String toAccount,
required TokenValue tokenValue,
String memo = '',
required Networks network,
required Network network,
}) async {
final contractName = tokenValue.tokenModel.contract;
final actionName = 'transfer';
Expand All @@ -77,7 +77,7 @@ class EOSService {

Future<Result<dynamic>> deleteBlockchainAccount({
required String accountName,
required Networks network,
required Network network,
}) async {
throw 'TBD - implement this';
// final action = createChangePermissionsAction(accountName, 'owner', ['keys'], ['accounts']);
Expand All @@ -87,7 +87,7 @@ class EOSService {
Future<Result<dynamic>> sendTransaction({
required EOSTransaction eosTransaction,
required String accountName,
required Networks network,
required Network network,
}) async {
final actions = eosTransaction.actions.map((e) => e.toEosAction).toList();

Expand Down
2 changes: 1 addition & 1 deletion lib/core/network/api/services/dao_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class DaoService {

Future<List<DaoData>> getDaos({
required String accountName,
required Networks network,
required Network network,
}) async {
final String query =
'{"query":"query profileDhos(\$username: String!, \$first: Int, \$offset: Int) { getMember(details_member_n: \$username) { docId __typename createdDate details_member_n memberofAggregate { count } memberof(first: \$first, offset: \$offset) { ... on Dao { docId details_daoName_n settings { settings_daoTitle_s settings_isHypha_i settings_logo_s settings_daoUrl_s } } } applicantof { ... on Dao { details_daoName_n settings { settings_daoTitle_s settings_daoUrl_s } } } } }","variables":{"username":"$accountName"}}';
Expand Down
4 changes: 2 additions & 2 deletions lib/core/network/api/services/hypha_member_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class HyphaMemberService {
/// Find a hypha accounts starting with prefix
Future<Result<List<String>, HyphaError>> findHyphaAccounts({
required String prefix,
required Networks network,
required Network network,
}) async {
try {
final daoContract = remoteConfigService.daoContract(network: network);
Expand All @@ -61,7 +61,7 @@ class HyphaMemberService {

Future<Result<bool, HyphaError>> isMember({
required String account,
required Networks network,
required Network network,
}) async {
try {
final daoContract = remoteConfigService.daoContract(network: network);
Expand Down
2 changes: 1 addition & 1 deletion lib/core/network/api/services/invite_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class InviteService {
Future<Result<dynamic>> redeemInvite({
required String account,
required String secret,
required Networks network,
required Network network,
}) async {
final contractName = eosService.remoteConfigService.inviteContract(network: network);
final actionName = 'redeeminvite';
Expand Down
2 changes: 1 addition & 1 deletion lib/core/network/api/services/pay_cpu_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class PayForCpuService {
/// Usage: preload the payCpuAction for any member who is a Hypha member - see HyphaMemberService
EOSAction payCpuAction({
required String account,
required Networks network,
required Network network,
}) {
final contractName = eosService.remoteConfigService.payCpuContract(network: network);
final action = EOSAction()
Expand Down
64 changes: 43 additions & 21 deletions lib/core/network/api/services/remote_config_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,21 @@ import 'dart:convert';
import 'package:firebase_remote_config/firebase_remote_config.dart';
import 'package:flutter/services.dart';

enum Networks { telos, telosTestnet, eos, eosTestnet }
enum Network {
n13 marked this conversation as resolved.
Show resolved Hide resolved
telos,
telosTestnet,
eos,
eosTestnet;

static Network fromString(String label) {
return values.firstWhere(
(v) => v.name == label,
orElse: () => Network.telos,
);
}
}

const Networks _defaultNetwork = Networks.telos;
const Network _defaultNetwork = Network.telos;

/// Encapsulates everything to do with remote configuration
class RemoteConfigService {
Expand All @@ -20,12 +32,12 @@ class RemoteConfigService {
return json.decode(FirebaseRemoteConfig.instance.getValue(param).asString());
}

Map<String, dynamic> _pppService({Networks? network}) {
Map<String, dynamic> _pppService({Network? network}) {
network = network ?? _defaultNetwork;
return _getMap('profileService')[network.name];
}

Map<String, dynamic> _getNetworkConfig({Networks? network}) {
Map<String, dynamic> _getNetworkConfig({Network? network}) {
network = network ?? _defaultNetwork;
final conf = _getMap('networks');
final networkFromConfig = conf[network.name];
Expand All @@ -37,67 +49,77 @@ class RemoteConfigService {

// base url - read URL
// network: default is Telos mainnet
String baseUrl({Networks? network}) {
String baseUrl({Network? network}) {
final networkConfig = _getNetworkConfig(network: network);
final endpoint = networkConfig['endpoint'];
return endpoint;
}

// Node for push transactions - should be a fast server to prevent timeouts
// network: default is Telos mainnet.
String pushTransactionNodeUrl({required Networks network}) {
String pushTransactionNodeUrl({required Network network}) {
final networkConfig = _getNetworkConfig(network: network);
final endpoint = networkConfig['fastEndpoint'];
return endpoint;
}

String graphQLEndpoint({required Networks network}) {
String graphQLEndpoint({required Network network}) {
final networkConfig = _getNetworkConfig(network: network);
final endpoint = networkConfig['graphQlEndpoint'];
return endpoint;
}

String loginContract({Networks? network}) {
String loginContract({Network? network}) {
final networkConfig = _getNetworkConfig(network: network);
return networkConfig['loginContract'];
}

String loginAction({Networks? network}) {
String loginAction({Network? network}) {
final networkConfig = _getNetworkConfig(network: network);
return networkConfig['loginAction'];
}

String inviteContract({Networks? network}) {
String inviteContract({Network? network}) {
final networkConfig = _getNetworkConfig(network: network);
return networkConfig['inviteContract'];
}

String payCpuContract({Networks? network}) {
String payCpuContract({Network? network}) {
final networkConfig = _getNetworkConfig(network: network);
return networkConfig['payCpuContract'];
}

String daoContract({Networks? network}) {
String daoContract({Network? network}) {
final networkConfig = _getNetworkConfig(network: network);
return networkConfig['daoContract'];
}

bool get isSignUpEnabled => FirebaseRemoteConfig.instance.getBool('signUpEnabled');

bool get isWalletEnabled => FirebaseRemoteConfig.instance.getBool('walletEnabled');

// PPP Profile Service Backend
String get profileServiceEndpoint => FirebaseRemoteConfig.instance.getString('profileServiceEndpoint');

String get accountCreatorEndpoint => FirebaseRemoteConfig.instance.getString('accountCreatorEndpoint');

// PPP Service AWS
String get awsProfileServiceEndpoint => _pppService()['awsProfileServiceEndpoint'];

String get pppEndpoint => _pppService()['awsProfileServiceEndpoint'];

String get identityPoolId => _pppService()['identityPoolId'];

String get userPoolId => _pppService()['userPoolId'];

String get clientId => _pppService()['clientId'];

String get pppOriginAppId => _pppService()['pppOriginAppId'];

String get pppRegion => _pppService()['region'];

String get pppS3Region => _pppService()['s3Region'];

String get pppS3Bucket => _pppService()['s3Bucket'];

// TODO(NIK): find the best endpoints for EOS
Expand Down Expand Up @@ -157,10 +179,10 @@ class RemoteConfigService {
'accountCreatorEndpoint': 'http://34.236.29.152:9108',
'profileServiceEndpoint': 'http://34.236.29.152:9109',
'profileService': json.encode({
'telos': pppConfig.getProfileSeriviceConfig(Networks.telos),
'telosTestnet': pppConfig.getProfileSeriviceConfig(Networks.telosTestnet),
'eos': pppConfig.getProfileSeriviceConfig(Networks.eos),
'eosTestnet': pppConfig.getProfileSeriviceConfig(Networks.eosTestnet),
'telos': pppConfig.getProfileSeriviceConfig(Network.telos),
'telosTestnet': pppConfig.getProfileSeriviceConfig(Network.telosTestnet),
'eos': pppConfig.getProfileSeriviceConfig(Network.eos),
'eosTestnet': pppConfig.getProfileSeriviceConfig(Network.eosTestnet),
}),
'signUpEnabled': false,
'walletEnabled': false,
Expand All @@ -178,12 +200,12 @@ class RemoteConfigService {
}

extension MapExtensions on Map<String, dynamic> {
Map<String, dynamic> getProfileSeriviceConfig(Networks network) {
Map<String, dynamic> getProfileSeriviceConfig(Network network) {
final networkMap = {
Networks.telos: 'prod',
Networks.telosTestnet: 'test',
Networks.eos: 'eos',
Networks.eosTestnet: 'eosTestNet',
Network.telos: 'prod',
Network.telosTestnet: 'test',
Network.eos: 'eos',
Network.eosTestnet: 'eosTestNet',
};
final data = this[networkMap[network]];

Expand Down
2 changes: 2 additions & 0 deletions lib/core/network/models/user_profile_data.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:hypha_wallet/core/network/api/services/remote_config_service.dart';

part 'user_profile_data.freezed.dart';
part 'user_profile_data.g.dart';
Expand All @@ -9,6 +10,7 @@ class UserProfileData with _$UserProfileData {

factory UserProfileData({
required String accountName,
required Network network,
n13 marked this conversation as resolved.
Show resolved Hide resolved
@Default(null) String? userImage,
@Default(null) String? bio,
@Default(null) String? userName,
Expand Down
Loading
Loading