Skip to content

Commit

Permalink
feat: Fetch verifier metadata from link #3009
Browse files Browse the repository at this point in the history
  • Loading branch information
bibash28 committed Nov 4, 2024
1 parent 3ab5466 commit b67c1cd
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 49 deletions.
5 changes: 5 additions & 0 deletions lib/app/shared/constants/parameters.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ class Parameters {
// 'https://app.altme.io/wallet_issuer' for altme
static const String walletIssuer = 'https://app.altme.io/wallet_issuer';

// 'https://app.talao.co/wallet-issuer/.well-known/openid-configuration'for talao
// 'https://app.altme.io/wallet-issuer/.well-known/openid-configuration' for altme
static const String walletMetadataForVerifier =
'https://app.altme.io/wallet-issuer/.well-known/openid-configuration';

static const DidKeyType didKeyTypeForEbsiV3 = DidKeyType.ebsiv3;
static const DidKeyType didKeyTypeForEbsiV4 = DidKeyType.ebsiv4;
static const DidKeyType didKeyTypeForDefault = DidKeyType.edDSA;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:convert';

import 'package:altme/app/app.dart';
import 'package:altme/dashboard/dashboard.dart';
import 'package:altme/dashboard/drawer/ssi/verifiers_metadata/view/verifiers_metadata_page.dart';
import 'package:flutter/material.dart';

class Oidc4vcSettingMenu extends StatelessWidget {
Expand Down Expand Up @@ -65,15 +66,7 @@ class Oidc4vcSettingMenuView extends StatelessWidget {
DrawerItem(
title: 'Wallet metadata for verifiers',
onTap: () {
final value = const JsonEncoder.withIndent(' ').convert(
ConstantsJson.walletMetadataForVerifiers,
);
Navigator.of(context).push<void>(
JsonViewerPage.route(
title: 'Wallet metadata for verifiers',
data: value,
),
);
Navigator.of(context).push<void>(VerifiersMetadataPage.route());
},
),
],
Expand Down
1 change: 1 addition & 0 deletions lib/dashboard/drawer/ssi/ssi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export 'manage_did/manage_did.dart';
export 'oidc4vc_settngs/oidc4vc_settings.dart';
export 'src/src.dart';
export 'trust_framework/trust_framework.dart';
export 'verifiers_metadata/verifiers_metadata.dart';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'view/verifiers_metadata_page.dart';
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import 'dart:convert';

import 'package:altme/app/app.dart';
import 'package:altme/dashboard/dashboard.dart';
import 'package:dio/dio.dart';

import 'package:flutter/material.dart';
import 'package:secure_storage/secure_storage.dart';

class VerifiersMetadataPage extends StatelessWidget {
const VerifiersMetadataPage({super.key});

static Route<dynamic> route() => MaterialPageRoute<void>(
builder: (_) => const VerifiersMetadataPage(),
settings: const RouteSettings(name: '/VerifiersMetadataPage'),
);

@override
Widget build(BuildContext context) {
return const VerifiersMetadataView();
}
}

class VerifiersMetadataView extends StatelessWidget {
const VerifiersMetadataView({super.key});

Future<String> getData() async {
try {
final response = await DioClient(
secureStorageProvider: getSecureStorage,
dio: Dio(),
).get(Parameters.walletMetadataForVerifier);
final data = response is String
? jsonDecode(response) as Map<String, dynamic>
: response as Map<String, dynamic>;
final value = const JsonEncoder.withIndent(' ').convert(data);
return value;
} catch (e) {
return '';
}
}

@override
Widget build(BuildContext context) {
return BasePage(
title: 'Wallet metadata for verifiers',
titleAlignment: Alignment.topCenter,
titleLeading: const BackLeadingButton(),
padding: const EdgeInsets.only(
top: 0,
bottom: Sizes.spaceSmall,
left: Sizes.spaceSmall,
right: Sizes.spaceSmall,
),
secureScreen: true,
body: FutureBuilder<String>(
future: getData(),
builder: (context, snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.done:
return JsonViewWidget(data: snapshot.data.toString());

case ConnectionState.waiting:
case ConnectionState.none:
case ConnectionState.active:
return const Center(child: CircularProgressIndicator());
}
},
),
);
}
}
1 change: 1 addition & 0 deletions lib/dashboard/json_viewer/json_viewer.dart
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export 'view/json_viewer_page.dart';
export 'widget/json_viewer_widget.dart';
42 changes: 2 additions & 40 deletions lib/dashboard/json_viewer/view/json_viewer_page.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:altme/app/app.dart';
import 'package:altme/dashboard/dashboard.dart';
import 'package:flutter/material.dart';

class JsonViewerPage extends StatelessWidget {
Expand Down Expand Up @@ -44,52 +45,13 @@ class JsonViewerView extends StatelessWidget {

@override
Widget build(BuildContext context) {
final pattern = RegExp(r'<b>(.*?)<\/b>');
final matches = pattern.allMatches(data);

final textSpans = <TextSpan>[];
int currentIndex = 0;

for (final match in matches) {
final plainText = data.substring(currentIndex, match.start);
final boldText = data.substring(match.start + 3, match.end - 4);
textSpans.add(
TextSpan(
text: plainText,
style: Theme.of(context).textTheme.bodyMedium,
),
);
textSpans.add(
TextSpan(
text: boldText,
style: Theme.of(context)
.textTheme
.bodyMedium!
.copyWith(fontWeight: FontWeight.w700),
),
);
currentIndex = match.end;
}

if (currentIndex < data.length) {
final remainingText = data.substring(currentIndex);
textSpans.add(
TextSpan(
text: remainingText,
style: Theme.of(context).textTheme.bodyMedium,
),
);
}

return BasePage(
title: title,
titleAlignment: Alignment.topCenter,
scrollView: true,
titleLeading: const BackLeadingButton(),
padding: const EdgeInsets.symmetric(horizontal: 10),
body: RichText(
text: TextSpan(children: textSpans),
),
body: JsonViewWidget(data: data),
);
}
}
49 changes: 49 additions & 0 deletions lib/dashboard/json_viewer/widget/json_viewer_widget.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import 'package:flutter/material.dart';

class JsonViewWidget extends StatelessWidget {
const JsonViewWidget({super.key, required this.data});

final String data;

@override
Widget build(BuildContext context) {
final pattern = RegExp(r'<b>(.*?)<\/b>');
final matches = pattern.allMatches(data);

final textSpans = <TextSpan>[];
int currentIndex = 0;

for (final match in matches) {
final plainText = data.substring(currentIndex, match.start);
final boldText = data.substring(match.start + 3, match.end - 4);
textSpans.add(
TextSpan(
text: plainText,
style: Theme.of(context).textTheme.bodyMedium,
),
);
textSpans.add(
TextSpan(
text: boldText,
style: Theme.of(context)
.textTheme
.bodyMedium!
.copyWith(fontWeight: FontWeight.w700),
),
);
currentIndex = match.end;
}

if (currentIndex < data.length) {
final remainingText = data.substring(currentIndex);
textSpans.add(
TextSpan(
text: remainingText,
style: Theme.of(context).textTheme.bodyMedium,
),
);
}

return RichText(text: TextSpan(children: textSpans));
}
}
1 change: 1 addition & 0 deletions lib/dashboard/json_viewer/widget/widget.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'json_viewer_widget.dart';

0 comments on commit b67c1cd

Please sign in to comment.