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

Generalize to handle token standards other than ERC20 (e.g. eosio) #1

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Mobile app that serves as a Point of Sale application/Kiosk for our NFC wallets.
The app provides "tap to pay" and "tap to top-up" functionality for our NFC wallets.

https://citizenwallet.notion.site/Kiosk-manual-1d5b408be10b446b90ed5e53978dd02e

## Getting Started

Expand All @@ -15,3 +16,4 @@ A few resources to get you started if this is your first Flutter project:
For help getting started with Flutter development, view the
[online documentation](https://docs.flutter.dev/), which offers tutorials,
samples, guidance on mobile development, and a full API reference.

5 changes: 5 additions & 0 deletions android/keystore.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
storePassword=dummy
keyPassword=dummy
keyAlias=dummy
storeFile=dummy

31 changes: 30 additions & 1 deletion assets/config/v3/communities.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -1359,5 +1359,34 @@
}
],
"version": 1
}
},
{
"community": {
"name": "SEEDS",
"description": "This is a community for Chuck",
"url": "https://joinseeds.earth",
"alias": "chuck.citizenwallet.xyz",
"custom_domain": "",
"logo": "https://raw.githubusercontent.com/JoinSEEDS/seeds_light_wallet/master/assets/images/seeds_logo.svg",
"theme": {
"primary": "#00c800"
}
},
"token": {
"standard": "eosio",
"name": "Seeds",
"address": "token.seeds",
"symbol": "SEEDS",
"decimals": 4
},
"scan": {
"url": "https://explorer.telos.net/network",
"name": "Telos zero"
},
"node": {
"url": "https://mainnet.telos.net",
"invoice_url": "https://cc42.xyz/invoice"
},
"version": 1
}
]
3 changes: 2 additions & 1 deletion lib/router/bottom_tabs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ class CustomBottomAppBar extends StatelessWidget {
enabled: !redeeming,
offset: const Offset(0, 40),
itemBuilder: (BuildContext context) => configs
.where((c) => c.cards != null)
.where((c) => c.cards != null
|| c.token.standard == "eosio")
.map<PopupMenuEntry<Config>>(
(c) => PopupMenuItem<Config>(
value: c,
Expand Down
243 changes: 168 additions & 75 deletions lib/screens/pos/screen.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:http/http.dart' as http;
import 'package:provider/provider.dart';
import 'package:scanner/router/bottom_tabs.dart';
import 'package:scanner/screens/pos/tabs/amount/amount.dart';
Expand Down Expand Up @@ -89,85 +91,176 @@ class POSScreenState extends State<POSScreen>
return;
}

final deepLinkUrl = dotenv.env['WALLET_DEEPLINK_URL'];
if (deepLinkUrl == null) {
return;
}

_scanLogic.listenToBalance();

await showModalBottomSheet<void>(
context: context,
builder: (modalContext) {
final vendorAddress = modalContext.watch<ScanState>().vendorAddress;
final vendorBalance = modalContext.watch<ScanState>().vendorBalance;

String params =
'?address=$vendorAddress&alias=${config.community.alias}';

params += '&amount=$amount';
params += '&message=$description';

final compressedParams = compress(params);

final deepLink =
'$deepLinkUrl/#/?alias=${config.community.alias}&receiveParams=$compressedParams';

return Container(
height: height,
width: width,
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const Text(
'Scan to pay',
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
if (config.token.standard == "erc20") {
final deepLinkUrl = dotenv.env['WALLET_DEEPLINK_URL'];
if (deepLinkUrl == null) {
return;
}

_scanLogic.listenToBalance();

await showModalBottomSheet<void>(
context: context,
builder: (modalContext) {
final vendorAddress = modalContext.watch<ScanState>().vendorAddress;
final vendorBalance = modalContext.watch<ScanState>().vendorBalance;

String params =
'?address=$vendorAddress&alias=${config.community.alias}';

params += '&amount=$amount';
params += '&message=$description';

final compressedParams = compress(params);

final deepLink =
'$deepLinkUrl/#/?alias=${config.community.alias}&receiveParams=$compressedParams';

return Container(
height: height,
width: width,
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const Text(
'Scan to pay',
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
),
),
),
const SizedBox(height: 16),
QR(
data: deepLink,
size: width - 120,
),
const SizedBox(height: 16),
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
'$amount ${config.token.symbol}',
style: const TextStyle(
fontSize: 22,
fontWeight: FontWeight.normal,
const SizedBox(height: 16),
QR(
data: deepLink,
size: width - 120,
),
const SizedBox(height: 16),
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
'$amount ${config.token.symbol}',
style: const TextStyle(
fontSize: 22,
fontWeight: FontWeight.normal,
),
),
),
],
),
const SizedBox(height: 16),
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
description,
style: const TextStyle(
fontSize: 22,
fontWeight: FontWeight.normal,
],
),
const SizedBox(height: 16),
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
description,
style: const TextStyle(
fontSize: 22,
fontWeight: FontWeight.normal,
),
),
],
),
],
),
);
},
);

_scanLogic.stopListenToBalance();
} else if (config.token.standard == "eosio"){
// TODO get legit vendor address (12 character eosio account name)
final vendorAddress = "vendor";

// TODO refactor API call - maybe in web3Service
String invoiceQuery =
'?to=$vendorAddress&quantity=$amount&memo=$description&tokenContract=${config.token.address}'+
'&tokenSymbol=${config.token.symbol}&digitsPrecision=${config.token.decimals}';
Map<String, String>? headers;
final mergedHeaders = <String, String>{
'Accept': 'application/json',
'Content-Type': 'application/json; charset=UTF-8',
};
if (headers != null) {
mergedHeaders.addAll(headers);
}
final gg = Uri.parse('${config.node!.invoiceUrl}$invoiceQuery');

final response = await http
.get(
Uri.parse('${config.node!.invoiceUrl}$invoiceQuery'),
headers: mergedHeaders,
)
.timeout(const Duration(seconds: 10));

if (response.statusCode < 200 || response.statusCode >= 300) {
throw Exception('[${response.statusCode}] ${response.reasonPhrase}');
}

String esrData = jsonDecode(utf8.decode(response.bodyBytes))['esr'];

await showModalBottomSheet<void>(
context: context,
builder: (modalContext) {


return Container(
height: height,
width: width,
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const Text(
'Scan to pay',
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
),
],
),
],
),
);
},
);

_scanLogic.stopListenToBalance();
),
const SizedBox(height: 16),
QR(
data: esrData,
size: width - 120,
),
const SizedBox(height: 16),
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
'$amount ${config.token.symbol}',
style: const TextStyle(
fontSize: 22,
fontWeight: FontWeight.normal,
),
),
],
),
const SizedBox(height: 16),
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
description,
style: const TextStyle(
fontSize: 22,
fontWeight: FontWeight.normal,
),
),
],
),
],
),
);
},
);
}
}

void handleScan(
Expand Down
Loading