Skip to content

Commit

Permalink
Feature #19 web support (#22)
Browse files Browse the repository at this point in the history
* feat(#19): web support

* feat(#19): updated readme and updated package version

* feat(#19): updated manifest file
  • Loading branch information
allanclempe authored Sep 20, 2021
1 parent 6af3c1b commit 468e064
Show file tree
Hide file tree
Showing 15 changed files with 230 additions and 28 deletions.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ A digital wallet app, developed in dart language and flutter framework. The idea
- [QR code scanner](https://github.com/juliuscanute/qr_code_scanner) to scan addresses
- [Web3Dart](https://github.com/simolus3/web3dart) to interact with Ethereum blockchain
- [Flutter hooks](https://github.com/rrousselGit/flutter_hooks) to manage widget life-cycle.
- [Solidity](https://github.com/allanclempe/ether-wallet-contract) smart contract

| Wallet | Change network | Transfer tokens |
| :--------------------------------------------------------------: | :-------------------------------------------------------------------: | :----------------------------------------------------------------------: |
Expand All @@ -30,6 +31,12 @@ $ flutter packages pub run build_runner build
$ flutter run
```

running on the browser

```bash
$ flutter run -d chrome
```

How to run tests

```bash
Expand All @@ -48,16 +55,19 @@ After setting up your wallet, you will need some tokens to play with. Use the li

**_Transfer test Ether to your wallet_**

Also to process transactions on the network, you will also need ETH to pay transaction fees, called gas. You also can claim some using the link below.
To process transactions on the network, you will also need ETH to pay transaction fees, called gas. You also can claim some to test your wallet. Each network has its own faucet.

[https://faucet.ropsten.be/](https://faucet.ropsten.be/)
- Ropsten: [https://faucet.ropsten.be/](https://faucet.ropsten.be/)
- Polygon (old MATIC): [https://faucet.polygon.technology/](https://faucet.polygon.technology/)
- BSC: [https://testnet.binance.org/faucet-smart](https://testnet.binance.org/faucet-smart)

just be patient, the transaction might take a while to be processed.

### The smart contract

Feel free to check out the smart contract used in this project [https://github.com/allanclempe/ether-wallet-contract](https://github.com/allanclempe/ether-wallet-contract)


### Buy me a coffee

If you enjoy my work, a small donation would be greatly appreciated.
Expand Down
12 changes: 12 additions & 0 deletions android/app/src/main/res/drawable-v21/launch_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="?android:colorBackground" />

<!-- You can insert your own image assets here -->
<!-- <item>
<bitmap
android:gravity="center"
android:src="@mipmap/launch_image" />
</item> -->
</layer-list>
18 changes: 18 additions & 0 deletions android/app/src/main/res/values-night/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is on -->
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
Flutter draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item>
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Flutter UI initializes, as well as behind your Flutter UI while its
running.
This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>
15 changes: 9 additions & 6 deletions lib/components/form/paper_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ class PaperForm extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Form(
child: Padding(
padding: EdgeInsets.all(padding),
child: Column(children: [
...children,
..._buildButtons(),
]),
child: Container(
constraints: const BoxConstraints(maxWidth: 480),
child: Padding(
padding: EdgeInsets.all(padding),
child: Column(children: [
...children,
..._buildButtons(),
]),
),
),
);
}
Expand Down
4 changes: 3 additions & 1 deletion lib/components/wallet/balance.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:etherwallet/components/copyButton/copy_button.dart';
import 'package:etherwallet/utils/eth_amount_formatter.dart';
import 'package:flutter/material.dart';
import 'package:qr_flutter/qr_flutter.dart';
import 'package:flutter/foundation.dart' show kIsWeb;

class Balance extends StatelessWidget {
const Balance({
Expand Down Expand Up @@ -31,7 +32,8 @@ class Balance extends StatelessWidget {
text: const Text('Copy address'),
value: address,
),
if (address != null && mediaQuery.orientation == Orientation.portrait)
if (address != null &&
(mediaQuery.orientation == Orientation.portrait || kIsWeb))
QrImage(
data: address!,
size: 150.0,
Expand Down
1 change: 1 addition & 0 deletions lib/components/wallet/display_mnemonic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class DisplayMnemonic extends HookWidget {
Widget build(BuildContext context) {
return Center(
child: Container(
constraints: const BoxConstraints(maxWidth: 420),
margin: const EdgeInsets.all(25),
child: SingleChildScrollView(
child: Column(
Expand Down
10 changes: 9 additions & 1 deletion lib/service/contract_locator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import 'package:etherwallet/utils/contract_parser.dart';
import 'package:web3dart/web3dart.dart';
import 'package:web_socket_channel/io.dart';
import 'package:http/http.dart';
import 'package:web_socket_channel/web_socket_channel.dart';
import 'package:flutter/foundation.dart' show kIsWeb;

class ContractLocator {
ContractLocator._();
Expand All @@ -29,7 +31,13 @@ class ContractLocator {
final wsAddress = networkConfig.web3RdpUrl;
final client = Web3Client(networkConfig.web3HttpUrl, Client(),
socketConnector: wsAddress != null
? () => IOWebSocketChannel.connect(wsAddress).cast<String>()
? () {
if (kIsWeb)
return WebSocketChannel.connect(Uri.parse(wsAddress))
.cast<String>();

return IOWebSocketChannel.connect(wsAddress).cast<String>();
}
: null);

final contract = await ContractParser.fromAssets(
Expand Down
28 changes: 15 additions & 13 deletions lib/wallet_transfer_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:etherwallet/context/transfer/wallet_transfer_provider.dart';
import 'package:etherwallet/model/network_type.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter/foundation.dart' show kIsWeb;

import 'components/wallet/loading.dart';

Expand All @@ -26,19 +27,20 @@ class WalletTransferPage extends HookWidget {
appBar: AppBar(
title: Text(title),
actions: <Widget>[
IconButton(
icon: const Icon(Icons.camera_alt),
onPressed: !transferStore.state.loading
? () {
Navigator.of(context).pushNamed(
'/qrcode_reader',
arguments: (scannedAddress) {
qrcodeAddress.value = scannedAddress.toString();
},
);
}
: null,
),
if (!kIsWeb)
IconButton(
icon: const Icon(Icons.camera_alt),
onPressed: !transferStore.state.loading
? () {
Navigator.of(context).pushNamed(
'/qrcode_reader',
arguments: (scannedAddress) {
qrcodeAddress.value = scannedAddress.toString();
},
);
}
: null,
),
],
),
body: transferStore.state.loading
Expand Down
6 changes: 3 additions & 3 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ packages:
name: firebase_analytics
url: "https://pub.dartlang.org"
source: hosted
version: "8.0.4"
version: "8.2.0"
firebase_analytics_platform_interface:
dependency: transitive
description:
Expand All @@ -252,7 +252,7 @@ packages:
name: firebase_core
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.1"
version: "1.4.0"
firebase_core_platform_interface:
dependency: transitive
description:
Expand All @@ -266,7 +266,7 @@ packages:
name: firebase_core_web
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.3"
version: "1.1.0"
fixnum:
dependency: transitive
description:
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 2.1.0+8
version: 2.2.0+9

environment:
sdk: ">=2.12.0 <3.0.0"
Expand All @@ -41,7 +41,7 @@ dependencies:
intl: ^0.16.1
flutter_spinkit: ^5.0.0
qr_code_scanner: ^0.4.0
firebase_analytics: ^8.0.4
firebase_analytics: ^8.2.0
url_launcher: ^6.0.2
flutter_hooks: ^0.16.0
built_value: ^8.0.6
Expand Down
Binary file added web/favicon.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 added web/icons/Icon-192.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 added web/icons/Icon-512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
123 changes: 123 additions & 0 deletions web/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<!DOCTYPE html>
<html>
<head>
<!--
If you are serving your web app in a path other than the root, change the
href value below to reflect the base path you are serving from.
The path provided below has to start and end with a slash "/" in order for
it to work correctly.
For more details:
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
-->
<base href="/" />

<meta charset="UTF-8" />
<meta content="IE=Edge" http-equiv="X-UA-Compatible" />
<meta name="description" content="A new Flutter project." />

<!-- iOS meta tags & icons -->
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta name="apple-mobile-web-app-title" content="etherwallet" />
<link rel="apple-touch-icon" href="icons/Icon-192.png" />

<title>etherwallet</title>
<link rel="manifest" href="manifest.json" />

<!-- The core Firebase JS SDK is always required and must be listed first -->
<script src="https://www.gstatic.com/firebasejs/8.9.1/firebase-app.js"></script>

<!-- TODO: Add SDKs for Firebase products that you want to use
https://firebase.google.com/docs/web/setup#available-libraries -->
<script src="https://www.gstatic.com/firebasejs/8.9.1/firebase-analytics.js"></script>

<script>
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
var firebaseConfig = {
apiKey: "AIzaSyDWvJXaUYfFKdTHNxv5EA0iNEuCUAY7Nbo",
authDomain: "etherwallet-18c58.firebaseapp.com",
databaseURL: "https://etherwallet-18c58.firebaseio.com",
projectId: "etherwallet-18c58",
storageBucket: "etherwallet-18c58.appspot.com",
messagingSenderId: "1087248227022",
appId: "1:1087248227022:web:df8ff8ba4d302b361a4e9f",
measurementId: "G-V04M927HSD",
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
firebase.analytics();
</script>
</head>
<body>
<!-- This script installs service_worker.js to provide PWA functionality to
application. For more information, see:
https://developers.google.com/web/fundamentals/primers/service-workers -->
<script>
var serviceWorkerVersion = null;
var scriptLoaded = false;
function loadMainDartJs() {
if (scriptLoaded) {
return;
}
scriptLoaded = true;
var scriptTag = document.createElement("script");
scriptTag.src = "main.dart.js";
scriptTag.type = "application/javascript";
document.body.append(scriptTag);
}

if ("serviceWorker" in navigator) {
// Service workers are supported. Use them.
window.addEventListener("load", function () {
// Wait for registration to finish before dropping the <script> tag.
// Otherwise, the browser will load the script multiple times,
// potentially different versions.
var serviceWorkerUrl =
"flutter_service_worker.js?v=" + serviceWorkerVersion;
navigator.serviceWorker.register(serviceWorkerUrl).then((reg) => {
function waitForActivation(serviceWorker) {
serviceWorker.addEventListener("statechange", () => {
if (serviceWorker.state == "activated") {
console.log("Installed new service worker.");
loadMainDartJs();
}
});
}
if (!reg.active && (reg.installing || reg.waiting)) {
// No active web worker and we have installed or are installing
// one for the first time. Simply wait for it to activate.
waitForActivation(reg.installing ?? reg.waiting);
} else if (!reg.active.scriptURL.endsWith(serviceWorkerVersion)) {
// When the app updates the serviceWorkerVersion changes, so we
// need to ask the service worker to update.
console.log("New service worker available.");
reg.update();
waitForActivation(reg.installing);
} else {
// Existing service worker is still good.
console.log("Loading app from service worker.");
loadMainDartJs();
}
});

// If service worker doesn't succeed in a reasonable amount of time,
// fallback to plaint <script> tag.
setTimeout(() => {
if (!scriptLoaded) {
console.warn(
"Failed to load app from service worker. Falling back to plain <script> tag."
);
loadMainDartJs();
}
}, 4000);
});
} else {
// Service workers not supported. Just drop the <script> tag.
loadMainDartJs();
}
</script>
</body>
</html>
23 changes: 23 additions & 0 deletions web/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "etherwallet",
"short_name": "etherwallet",
"start_url": ".",
"display": "standalone",
"background_color": "#0175C2",
"theme_color": "#0175C2",
"description": "Ethereum wallet using an ERC-20 smart contract.",
"orientation": "portrait-primary",
"prefer_related_applications": false,
"icons": [
{
"src": "icons/Icon-192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "icons/Icon-512.png",
"sizes": "512x512",
"type": "image/png"
}
]
}

0 comments on commit 468e064

Please sign in to comment.