Skip to content

Commit

Permalink
October (#2086)
Browse files Browse the repository at this point in the history
* feat: Remove endless loop while account renaming #2049

* refactor: Fix bug of not storing network changes #2064

* feat: Remove reward feature #2045

* version update

* feat: Rename wallet credential into wallet attestation #2079

* feat: Remove claim check in oidc4vc test

* feat: Update scope support string & Verify request if subject syntax type also enabled

* version update

* feat: Change image for wallet credential

* version update
  • Loading branch information
bibash28 authored Nov 13, 2023
1 parent 02c7e02 commit 01a1847
Show file tree
Hide file tree
Showing 24 changed files with 312 additions and 274 deletions.
Binary file modified assets/image/wallet-certificate-android.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/image/wallet-certificate-ios.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion lib/app/shared/constants/secure_storage_keys.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class SecureStorageKeys {
static const String polygonIdNetwork = 'profile/polygonIdNetwork';
static const String didKeyType = 'profile/didKeyType';

static const String blockchainNetworkKey = 'profile/blockchainNetwork';
static const String blockChainNetworksIndexing = 'blockChainNetworksIndexing';
static const String credentialKey = 'credential';

static const String ssiMnemonic = 'ssi/mnemonic';
Expand Down
2 changes: 1 addition & 1 deletion lib/app/shared/enum/status/app_status.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ enum AppStatus {
success,
idle,
goBack,
gotTokenReward,
//gotTokenReward,
}
7 changes: 4 additions & 3 deletions lib/app/shared/models/blockchain_network/tezos_network.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ class TezosNetwork extends BlockchainNetwork {
required super.rpcNodeUrl,
required String super.title,
required String super.subTitle,
required super.type,
super.apiKey,
}) : super(
type: BlockchainType.tezos,
);
});

factory TezosNetwork.fromJson(Map<String, dynamic> json) =>
_$TezosNetworkFromJson(json);

factory TezosNetwork.mainNet() => const TezosNetwork(
type: BlockchainType.tezos,
networkname: 'Mainnet',
apiUrl: Urls.tzktMainnetUrl,
rpcNodeUrl: Urls.mainnetRPC,
Expand All @@ -30,6 +30,7 @@ class TezosNetwork extends BlockchainNetwork {
);

factory TezosNetwork.ghostnet() => const TezosNetwork(
type: BlockchainType.tezos,
networkname: 'Ghostnet',
apiUrl: Urls.tzktGhostnetUrl,
rpcNodeUrl: Urls.ghostnetRPC,
Expand Down
11 changes: 6 additions & 5 deletions lib/app/view/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,6 @@ class App extends StatelessWidget {
);
},
),
BlocProvider<ManageNetworkCubit>(
create: (context) => ManageNetworkCubit(
secureStorageProvider: secure_storage.getSecureStorage,
),
),
BlocProvider<DIDCubit>(
create: (context) => DIDCubit(
secureStorageProvider: secure_storage.getSecureStorage,
Expand Down Expand Up @@ -130,6 +125,12 @@ class App extends StatelessWidget {
walletConnectCubit: context.read<WalletConnectCubit>(),
),
),
BlocProvider<ManageNetworkCubit>(
create: (context) => ManageNetworkCubit(
secureStorageProvider: secure_storage.getSecureStorage,
walletCubit: context.read<WalletCubit>(),
),
),
BlocProvider<PolygonIdCubit>(
create: (context) => PolygonIdCubit(
client: DioClient('', Dio()),
Expand Down
39 changes: 36 additions & 3 deletions lib/credentials/cubit/credentials_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -439,15 +439,46 @@ class CredentialsCubit extends Cubit<CredentialsState> {

/// update or create AssociatedAddres credential with new name
if (filteredCredentialList.isNotEmpty) {
final credential = await createAssociatedWalletCredential(
//find old id of the credential
final oldCredential = oldCredentialList.where((CredentialModel element) {
final credentialSubjectModel =
element.credentialPreview.credentialSubjectModel;

String? walletAddress;

if (credentialSubjectModel is EthereumAssociatedAddressModel) {
walletAddress = credentialSubjectModel.associatedAddress;
} else if (credentialSubjectModel is TezosAssociatedAddressModel) {
walletAddress = credentialSubjectModel.associatedAddress;
} else if (credentialSubjectModel is FantomAssociatedAddressModel) {
walletAddress = credentialSubjectModel.associatedAddress;
} else if (credentialSubjectModel is BinanceAssociatedAddressModel) {
walletAddress = credentialSubjectModel.associatedAddress;
} else if (credentialSubjectModel is PolygonAssociatedAddressModel) {
walletAddress = credentialSubjectModel.associatedAddress;
} else {
return false;
}

if (walletAddress != null &&
walletAddress == cryptoAccountData.walletAddress) {
return true;
}

return false;
}).first;

// final credential = state.credentials.where((element) => element.);
final credential = await createOrUpdateAssociatedWalletCredential(
blockchainType: blockchainType,
cryptoAccountData: cryptoAccountData,
oldId: oldCredential.id,
);
if (credential != null) {
await updateCredential(credential: credential);
}
} else {
final credential = await createAssociatedWalletCredential(
final credential = await createOrUpdateAssociatedWalletCredential(
blockchainType: blockchainType,
cryptoAccountData: cryptoAccountData,
);
Expand All @@ -457,16 +488,18 @@ class CredentialsCubit extends Cubit<CredentialsState> {
}
}

Future<CredentialModel?> createAssociatedWalletCredential({
Future<CredentialModel?> createOrUpdateAssociatedWalletCredential({
required BlockchainType blockchainType,
required CryptoAccountData cryptoAccountData,
String? oldId,
}) async {
return generateAssociatedWalletCredential(
cryptoAccountData: cryptoAccountData,
didCubit: didCubit,
didKitProvider: didKitProvider,
blockchainType: blockchainType,
keyGenerator: keyGenerator,
oldId: oldId,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class _ManageAccountsPageState extends State<ManageAccountsPage> {
final l10n = context.l10n;
final List<CryptoAccountData> cryptoAccount =
context.read<ManageAccountsCubit>().state.cryptoAccount.data;

final accountNameList = cryptoAccount.map((e) => e.name).toList();

final cryptoAccountData = cryptoAccount[index];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:convert';

import 'package:altme/app/app.dart';
import 'package:altme/wallet/cubit/wallet_cubit.dart';
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:json_annotation/json_annotation.dart';
Expand All @@ -11,47 +12,77 @@ part 'manage_network_cubit.g.dart';
part 'manage_network_state.dart';

class ManageNetworkCubit extends Cubit<ManageNetworkState> {
ManageNetworkCubit({required this.secureStorageProvider})
: super(ManageNetworkState(network: TezosNetwork.mainNet())) {
_load();
ManageNetworkCubit({
required this.secureStorageProvider,
required this.walletCubit,
}) : super(ManageNetworkState(network: TezosNetwork.mainNet())) {
loadNetwork();
}

final SecureStorageProvider secureStorageProvider;
final WalletCubit walletCubit;

Future<void> _load() async {
final blockchainNetworkJson =
await secureStorageProvider.get(SecureStorageKeys.blockchainNetworkKey);
Future<void> loadNetwork() async {
final blockchainType = walletCubit.state.currentAccount?.blockchainType;

late final BlockchainNetwork blockchainNetwork;
if (blockchainType == null) return;

late BlockchainNetwork blockchainNetwork;

final blockchainNetworkJson = await secureStorageProvider
.get(SecureStorageKeys.blockChainNetworksIndexing);

if (blockchainNetworkJson != null) {
final mJson = json.decode(blockchainNetworkJson) as Map<String, dynamic>;
if (mJson['chain'] != null) {
blockchainNetwork = EthereumNetwork.fromJson(mJson);
final jsonData =
json.decode(blockchainNetworkJson) as Map<String, dynamic>;

final key = blockchainType.name;

if (jsonData.containsKey(key)) {
final index = jsonData[key] as int;
blockchainNetwork = blockchainType.networks[index];
} else {
blockchainNetwork = BlockchainNetwork.fromJson(mJson);
// take index 0 of the current account
blockchainNetwork = blockchainType.networks[0];
}
} else {
blockchainNetwork = TezosNetwork.mainNet();
// take index 0 of the current account
blockchainNetwork = blockchainType.networks[0];
}

emit(state.copyWith(network: blockchainNetwork));
}

Future<void> setNetwork(BlockchainNetwork network) async {
if (network == state.network) return;
Map<String, dynamic> networkJson;
if (network is EthereumNetwork) {
networkJson = network.toJson();
} else if (network is TezosNetwork) {
networkJson = network.toJson();

final blockchainNetworkJson = await secureStorageProvider
.get(SecureStorageKeys.blockChainNetworksIndexing);

late Map<String, dynamic> jsonData;

if (blockchainNetworkJson != null) {
jsonData = json.decode(blockchainNetworkJson) as Map<String, dynamic>;
} else {
networkJson = network.toJson();
jsonData = <String, dynamic>{};
}

final blockchainType = network.type;
final supportedNetworks = blockchainType.networks;
final key = blockchainType.name;

final index = supportedNetworks.indexOf(network);

/// map with index is saved
/// {'tezos': 1 , 'ethereum': 1}
jsonData[key] = index;

await secureStorageProvider.set(
SecureStorageKeys.blockchainNetworkKey,
jsonEncode(networkJson),
SecureStorageKeys.blockChainNetworksIndexing,
jsonEncode(jsonData),
);

emit(state.copyWith(network: network));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ManageNetworkPage extends StatelessWidget {
builder: (context, state) {
final blockchainType =
context.read<WalletCubit>().state.currentAccount!.blockchainType;
final allNetworks = blockchainType.networks;
final currentNetworkList = blockchainType.networks;

return BackgroundCard(
child: Column(
Expand All @@ -41,27 +41,30 @@ class ManageNetworkPage extends StatelessWidget {
),
),
const SizedBox(height: 15),
...List.generate(allNetworks.length, (index) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
NetworkSelector(
network: allNetworks[index],
groupValue: state.network,
),
Padding(
padding: const EdgeInsets.symmetric(
horizontal: Sizes.spaceSmall,
vertical: Sizes.spaceXSmall,
...List.generate(
currentNetworkList.length,
(index) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
NetworkSelector(
network: currentNetworkList[index],
groupValue: state.network,
),
child: Divider(
height: 0.2,
color: Theme.of(context).colorScheme.borderColor,
Padding(
padding: const EdgeInsets.symmetric(
horizontal: Sizes.spaceSmall,
vertical: Sizes.spaceXSmall,
),
child: Divider(
height: 0.2,
color: Theme.of(context).colorScheme.borderColor,
),
),
),
],
);
}),
],
);
},
),
],
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ class NetworkSelector extends StatelessWidget {

@override
Widget build(BuildContext context) {
return BlocConsumer<ManageNetworkCubit, ManageNetworkState>(
listener: (context, state) {},
return BlocBuilder<ManageNetworkCubit, ManageNetworkState>(
builder: (context, state) {
return RadioListTile(
value: network,
Expand Down
Loading

0 comments on commit 01a1847

Please sign in to comment.