Skip to content

Commit

Permalink
updates for stamping implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Raviramnani1 committed Sep 2, 2024
1 parent ff2566b commit 9660cb7
Show file tree
Hide file tree
Showing 7 changed files with 247 additions and 77 deletions.
13 changes: 9 additions & 4 deletions wallet/lib/model/event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ class Events extends Equatable {
final String description;
final String numberOfTickets;
final String price;
final String? challenge;
final List<PerksModel>? listOfPerks;
final String isFreeDrops;
final String cookbookID;
final String step;
final IBCCoins denom;
String ownerAddress = "";
String owner = "";
bool isStamped = false;

Events({
this.id,
Expand Down Expand Up @@ -58,14 +58,14 @@ class Events extends Equatable {
///* other
this.cookbookID = '',
this.recipeID = '',
this.challenge,

///* for tracking where its save as draft
this.step = '',

///*
this.ownerAddress = "",
this.owner = '',
this.isStamped = false,
});

Map<String, dynamic> toJson() {
Expand All @@ -90,6 +90,7 @@ class Events extends Equatable {
map['price'] = price;
map['isFreeDrops'] = isFreeDrops;
map['cookbookID'] = cookbookID;
map['challenge'] = challenge ?? '';
map['step'] = step;
map['denom'] = denom.toString();
map['listOfPerks'] = perks;
Expand Down Expand Up @@ -117,6 +118,7 @@ class Events extends Equatable {
price: json['price'] as String,
isFreeDrops: json['isFreeDrops'] as String,
cookbookID: json['cookbookID'] as String,
challenge: json['challenge'] as String?,
step: json['step'] as String,
listOfPerks: listOfPerks,
denom: json['denom'].toString().toIBCCoinsEnumforEvent(),
Expand Down Expand Up @@ -161,6 +163,7 @@ class Events extends Equatable {
listOfPerks: listOfPerks,
cookbookID: map[kCookBookId]!,
recipeID: map[kRecipeId]!,
challenge: map[kChallenge],
denom: denom.isEmpty ? IBCCoins.upylon : denom.toIBCCoinsEnum(),
);
}
Expand All @@ -183,6 +186,7 @@ class Events extends Equatable {
case kPerks:
case kFreeDrop:
case kCookBookId:
case kChallenge:
case kRecipeId:
attributeValues[attribute.key] = attribute.value;
break;
Expand All @@ -203,11 +207,11 @@ class Events extends Equatable {

@override
List<Object?> get props =>
[eventName, hostName, thumbnail, startDate, endDate, startTime, endTime, location, description, numberOfTickets, price, listOfPerks, isFreeDrops, cookbookID, recipeID, step];
[eventName, hostName, thumbnail, startDate, endDate, startTime, endTime, location, description, numberOfTickets, price, listOfPerks, isFreeDrops, cookbookID, recipeID, step, challenge];

@override
String toString() {
return 'Event{eventName: $eventName, hostName: $hostName, thumbnail: $thumbnail, startDate: $startDate, endDate: $endDate, startTime: $startTime, endTime: $endTime, location: $location, description: $description, numberOfTickets: $numberOfTickets, price: $price, listOfPerks: $listOfPerks, isFreeDrop: $isFreeDrops, cookbookID: $cookbookID, recipeID: $recipeID, step: $step}';
return 'Event{eventName: $eventName, hostName: $hostName, thumbnail: $thumbnail, startDate: $startDate, endDate: $endDate, startTime: $startTime, endTime: $endTime, location: $location, description: $description, numberOfTickets: $numberOfTickets, price: $price, listOfPerks: $listOfPerks, isFreeDrop: $isFreeDrops, cookbookID: $cookbookID, recipeID: $recipeID, step: $step, challenge: $challenge}';
}

static Future<Events?> eventFromRecipeId(String cookbookId, String recipeId) async {
Expand Down Expand Up @@ -238,6 +242,7 @@ const kPrice = "kPrice";
const kFreeDrop = "kFreeDrop";
const kRecipeId = "kRecipeId";
const kCookBookId = "kCookBookId";
const kChallenge = "kChallenge";
const kVersion = "v0.2.0";
const kUpylon = "upylon";
const kPylonSymbol = 'upylon';
Expand Down
4 changes: 3 additions & 1 deletion wallet/lib/model/update_recipe_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class UpdateRecipeModel {
String nftPrice = "";
String denom = "";
int quantity = 0;
String challenge = "";

UpdateRecipeModel({
required this.recipe,
Expand All @@ -15,10 +16,11 @@ class UpdateRecipeModel {
required this.nftPrice,
required this.denom,
required this.quantity,
required this.challenge,
});

@override
String toString() {
return 'UpdateRecipeModel{recipe: $recipe, publicAddress: $publicAddress, enabledStatus: $enabledStatus, nftPrice: $nftPrice, denom: $denom, quantity: $quantity}';
return 'UpdateRecipeModel{recipe: $recipe, publicAddress: $publicAddress, enabledStatus: $enabledStatus, nftPrice: $nftPrice, denom: $denom, quantity: $quantity, challenge: $challenge}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -519,27 +519,27 @@ class OwnerViewViewModel extends ChangeNotifier {
}

Future<void> stampTicket({
required bool enabled,
required String cookbookId,
required String recipeId,
required Address creatorAddress,
required String challenge,
}) async {
final response = await repository.stampTicket(
cookBookId: CookbookId(cookbookId),
recipeId: RecipeId(recipeId),
creatorAddress: Address(events.ownerAddress),
creatorAddress: creatorAddress,
challenge: challenge,
);

if (response.isLeft()) {
throw response.getLeft();
}

events.isStamped = true;
notifyListeners();
}



void logEvent() {
repository.logUserJourney(screenName: AnalyticsScreenEvents.ownerView);
}
Expand Down
1 change: 1 addition & 0 deletions wallet/lib/pages/events/event_qr_code_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class _EventQrCodeScreenState extends State<EventQrCodeScreen> {
qrdata = jsonEncode({
'cookbookId': widget.events.cookbookID,
'recipeId': widget.events.recipeID,
'challenge': widget.events.challenge,
});
}

Expand Down
133 changes: 65 additions & 68 deletions wallet/lib/pages/events/mobile_scanner.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:flutter/material.dart';
import 'package:get_it/get_it.dart';
import 'package:mobile_scanner/mobile_scanner.dart';

import '../../utils/string_utils.dart';
import 'package:pylons_wallet/pages/events/stamping_screen.dart';
import '../../model/event.dart';
import '../detailed_asset_view/owner_view_view_model.dart';

class MobileQrScanner extends StatefulWidget {
Expand All @@ -13,96 +13,93 @@ class MobileQrScanner extends StatefulWidget {
}

class _MobileQrScannerState extends State<MobileQrScanner> {
OwnerViewViewModel ownerViewViewModel = GetIt.I.get();
final OwnerViewViewModel ownerViewViewModel = GetIt.I.get<OwnerViewViewModel>();
Barcode? _barcode;
bool isScanning = true;


Widget _buildBarcode(Barcode? value) {
if (value == null) {
Widget _buildBarcodeDisplay(Barcode? barcode) {
if (barcode == null) {
return const Text(
'Scan Ticket!',
overflow: TextOverflow.fade,
style: TextStyle(color: Colors.white),
overflow: TextOverflow.ellipsis,
style: TextStyle(color: Colors.white, fontSize: 18, fontWeight: FontWeight.bold),
);
}
print('QR Code Data: ${value.displayValue}');

return Text(
value.displayValue ?? 'No display value.',
overflow: TextOverflow.fade,
style: const TextStyle(color: Colors.white),
barcode.displayValue ?? 'No display value.',
overflow: TextOverflow.ellipsis,
style: const TextStyle(color: Colors.white, fontSize: 18, fontWeight: FontWeight.bold),
);
}

void _handleBarcode(BarcodeCapture barcodes) {
if (mounted) {
setState(() {
_barcode = barcodes.barcodes.firstOrNull;

if (_barcode != null) {
final qrData = _barcode!.displayValue ?? '';
final dataParts = qrData.split(',');

if (dataParts.length >= 2) {
final cookbookId = dataParts[0];
final recipeId = dataParts[1];


final challenge = StringUtils.generateRandomString(16);


stampTicket(cookbookId, recipeId, challenge);
} else {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Invalid QR code data.')),
);
}
void _handleBarcode(BarcodeCapture barcodeCapture) {
if (!isScanning) return;

setState(() {
if (barcodeCapture.barcodes.isNotEmpty) {
_barcode = barcodeCapture.barcodes[0];
final qrData = _barcode?.displayValue ?? '';
final dataParts = qrData.split(',');

if (dataParts.length >= 2) {
final cookbookId = dataParts[0];
final recipeId = dataParts[1];
final challenge = dataParts.length > 2 ? dataParts[2] : '';

Navigator.push(
context,
MaterialPageRoute(
builder: (context) => StampingScreen(
cookbookId: cookbookId,
recipeId: recipeId,
challenge: challenge,
ownerViewViewModel: ownerViewViewModel,
event: Events(eventName: 'Event Name', thumbnail: 'Thumbnail URL', description: 'Description'),
),
),
);
} else {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Invalid QR code data.')),
);
}
});
}
} else {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('No barcodes detected.')),
);
}
});
}

Future<void> stampTicket(String cookbookId, String recipeId, String challenge) async {
try {
await ownerViewViewModel.stampTicket(
enabled: true,
cookbookId: cookbookId,
recipeId: recipeId,
challenge: challenge,
);

ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Ticket with challenge $challenge stamped successfully!')),
);
} catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Failed to stamp ticket: $e')),
);
}
}


@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Ticket scanner')),
appBar: AppBar(
title: const Text('Ticket Scanner'),
backgroundColor: Colors.blueGrey[900],
),
backgroundColor: Colors.black,
body: Stack(
children: [
MobileScanner(
onDetect: _handleBarcode,
scanWindow: Rect.fromLTWH(
0,
0,
MediaQuery.of(context).size.width,
MediaQuery.of(context).size.height,
),
),
Align(
alignment: Alignment.bottomCenter,
Positioned(
bottom: 0,
left: 0,
right: 0,
child: Container(
alignment: Alignment.bottomCenter,
alignment: Alignment.center,
height: 100,
color: Colors.black.withOpacity(0.4),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Expanded(child: Center(child: _buildBarcode(_barcode))),
],
color: Colors.black.withOpacity(0.5),
child: Center(
child: _buildBarcodeDisplay(_barcode),
),
),
),
Expand Down
Loading

0 comments on commit 9660cb7

Please sign in to comment.