Skip to content

Commit 320738a

Browse files
committed
add account managing & WebViewWithExtension WIP
1 parent 57f048c commit 320738a

28 files changed

+18240
-77
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,5 @@ app.*.map.json
4242

4343
# Exceptions to above rules.
4444
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
45+
46+
js_as_extension/node_modules/

example/android/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,5 @@
4444
android:name="flutterEmbedding"
4545
android:value="2" />
4646
</application>
47+
<uses-permission android:name="android.permission.WAKE_LOCK" />
4748
</manifest>

example/lib/main.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
33
import 'package:polkawallet_sdk/api/types/networkParams.dart';
44
import 'package:polkawallet_sdk/polkawallet_sdk.dart';
55
import 'package:polkawallet_sdk_example/pages/account.dart';
6+
import 'package:polkawallet_sdk_example/pages/dAppPage.dart';
67
import 'package:polkawallet_sdk_example/pages/keyring.dart';
78
import 'package:polkawallet_sdk_example/pages/setting.dart';
89

@@ -63,6 +64,7 @@ class _MyAppState extends State<MyApp> {
6364
),
6465
home: MyHomePage(sdk, _sdkReady),
6566
routes: {
67+
DAppPage.route: (_) => DAppPage(sdk),
6668
KeyringPage.route: (_) => KeyringPage(sdk, _showResult),
6769
SettingPage.route: (_) => SettingPage(sdk, _showResult),
6870
AccountPage.route: (_) => AccountPage(sdk, _showResult),
@@ -144,6 +146,17 @@ class _MyHomePageState extends State<MyHomePage> {
144146
),
145147
),
146148
Divider(),
149+
ListTile(
150+
title: Text('WebViewWithExtension'),
151+
subtitle: Text('open polkassembly.io (DApp)'),
152+
trailing: trailing,
153+
onTap: () {
154+
if (!widget.sdkReady) return;
155+
Navigator.of(context).pushNamed(DAppPage.route,
156+
arguments: "https://apps.acala.network/#/loan");
157+
},
158+
),
159+
Divider(),
147160
ListTile(
148161
title: Text('sdk.keyring'),
149162
subtitle: Text('keyPairs management'),

example/lib/pages/dAppPage.dart

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import 'package:flutter/cupertino.dart';
2+
import 'package:flutter/material.dart';
3+
import 'package:polkawallet_sdk/polkawallet_sdk.dart';
4+
import 'package:polkawallet_sdk/webviewWithExtension/webviewWithExtension.dart';
5+
6+
class DAppPage extends StatefulWidget {
7+
DAppPage(this.sdk);
8+
9+
static const String route = '/extension/app';
10+
11+
final WalletSDK sdk;
12+
13+
@override
14+
_DAppPageState createState() => _DAppPageState();
15+
}
16+
17+
class _DAppPageState extends State<DAppPage> {
18+
bool _loading = true;
19+
20+
@override
21+
Widget build(BuildContext context) {
22+
final String url = ModalRoute.of(context).settings.arguments;
23+
return Scaffold(
24+
appBar: AppBar(
25+
title: Text(
26+
url,
27+
style: TextStyle(fontSize: 16),
28+
),
29+
centerTitle: true),
30+
body: SafeArea(
31+
child: Stack(
32+
children: [
33+
WebViewWithExtension(
34+
widget.sdk.api,
35+
url,
36+
onPageFinished: (url) {
37+
setState(() {
38+
_loading = false;
39+
});
40+
},
41+
onSignBytesRequest: (req) {
42+
print(req);
43+
return null;
44+
},
45+
onSignExtrinsicRequest: (req) {
46+
print(req);
47+
return null;
48+
},
49+
),
50+
_loading ? Center(child: CupertinoActivityIndicator()) : Container()
51+
],
52+
),
53+
),
54+
);
55+
}
56+
}

example/lib/pages/keyring.dart

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ class _KeyringPageState extends State<KeyringPage> {
4747
});
4848
}
4949

50+
Future<void> _getAccountList() async {
51+
final List<KeyPairData> ls = widget.sdk.api.keyring.keyPairs.toList();
52+
widget.showResult(
53+
context,
54+
'getAccountList',
55+
JsonEncoder.withIndent(' ').convert(ls.map((e) => e.address).toList()),
56+
);
57+
}
58+
5059
Future<void> _importFromMnemonic() async {
5160
setState(() {
5261
_submitting = true;
@@ -111,6 +120,21 @@ class _KeyringPageState extends State<KeyringPage> {
111120
});
112121
}
113122

123+
Future<void> _deleteAccount() async {
124+
setState(() {
125+
_submitting = true;
126+
});
127+
await widget.sdk.api.keyring.deleteAccount(_testAcc);
128+
widget.showResult(
129+
context,
130+
'deleteAccount',
131+
'ok',
132+
);
133+
setState(() {
134+
_submitting = false;
135+
});
136+
}
137+
114138
Future<void> _checkPassword() async {
115139
if (_testAcc == null) {
116140
print('should import keyPair to init test account.');
@@ -147,6 +171,19 @@ class _KeyringPageState extends State<KeyringPage> {
147171
});
148172
}
149173

174+
@override
175+
void initState() {
176+
super.initState();
177+
178+
WidgetsBinding.instance.addPostFrameCallback((_) {
179+
if (widget.sdk.api.keyring.keyPairs.length > 0) {
180+
setState(() {
181+
_testAcc = widget.sdk.api.keyring.keyPairs[0];
182+
});
183+
}
184+
});
185+
}
186+
150187
@override
151188
Widget build(BuildContext context) {
152189
return Scaffold(
@@ -165,6 +202,16 @@ class _KeyringPageState extends State<KeyringPage> {
165202
),
166203
),
167204
Divider(),
205+
ListTile(
206+
title: Text('getAccountList'),
207+
subtitle: Text('''
208+
sdk.api.keyring.accountList'''),
209+
trailing: SubmitButton(
210+
submitting: _submitting,
211+
call: _getAccountList,
212+
),
213+
),
214+
Divider(),
168215
ListTile(
169216
title: Text('importFromMnemonic'),
170217
subtitle: Text('''
@@ -210,6 +257,16 @@ sdk.api.keyring.importAccount(
210257
),
211258
),
212259
Divider(),
260+
ListTile(
261+
title: Text('deleteAccount'),
262+
subtitle: Text('''
263+
sdk.api.keyring.deleteAccount'''),
264+
trailing: SubmitButton(
265+
submitting: _submitting,
266+
call: _deleteAccount,
267+
),
268+
),
269+
Divider(),
213270
ListTile(
214271
title: Text('checkPassword'),
215272
subtitle: Text('''

example/pubspec.lock

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,27 @@ packages:
88
url: "https://pub.dartlang.org"
99
source: hosted
1010
version: "1.0.0"
11+
charcode:
12+
dependency: transitive
13+
description:
14+
name: charcode
15+
url: "https://pub.dartlang.org"
16+
source: hosted
17+
version: "1.1.3"
1118
collection:
1219
dependency: transitive
1320
description:
1421
name: collection
1522
url: "https://pub.dartlang.org"
1623
source: hosted
1724
version: "1.14.13"
25+
convert:
26+
dependency: transitive
27+
description:
28+
name: convert
29+
url: "https://pub.dartlang.org"
30+
source: hosted
31+
version: "2.1.1"
1832
cupertino_icons:
1933
dependency: "direct main"
2034
description:
@@ -34,6 +48,18 @@ packages:
3448
description: flutter
3549
source: sdk
3650
version: "0.0.0"
51+
flutter_aes_ecb_pkcs5:
52+
dependency: transitive
53+
description:
54+
name: flutter_aes_ecb_pkcs5
55+
url: "https://pub.dartlang.org"
56+
source: hosted
57+
version: "0.1.1"
58+
flutter_web_plugins:
59+
dependency: transitive
60+
description: flutter
61+
source: sdk
62+
version: "0.0.0"
3763
flutter_webview_plugin:
3864
dependency: transitive
3965
description:
@@ -139,6 +165,41 @@ packages:
139165
url: "https://pub.dartlang.org"
140166
source: hosted
141167
version: "3.0.13"
168+
shared_preferences:
169+
dependency: transitive
170+
description:
171+
name: shared_preferences
172+
url: "https://pub.dartlang.org"
173+
source: hosted
174+
version: "0.5.10"
175+
shared_preferences_linux:
176+
dependency: transitive
177+
description:
178+
name: shared_preferences_linux
179+
url: "https://pub.dartlang.org"
180+
source: hosted
181+
version: "0.0.2+2"
182+
shared_preferences_macos:
183+
dependency: transitive
184+
description:
185+
name: shared_preferences_macos
186+
url: "https://pub.dartlang.org"
187+
source: hosted
188+
version: "0.0.1+10"
189+
shared_preferences_platform_interface:
190+
dependency: transitive
191+
description:
192+
name: shared_preferences_platform_interface
193+
url: "https://pub.dartlang.org"
194+
source: hosted
195+
version: "1.0.4"
196+
shared_preferences_web:
197+
dependency: transitive
198+
description:
199+
name: shared_preferences_web
200+
url: "https://pub.dartlang.org"
201+
source: hosted
202+
version: "0.1.2+7"
142203
sky_engine:
143204
dependency: transitive
144205
description: flutter
@@ -158,6 +219,13 @@ packages:
158219
url: "https://pub.dartlang.org"
159220
source: hosted
160221
version: "2.0.8"
222+
webview_flutter:
223+
dependency: transitive
224+
description:
225+
name: webview_flutter
226+
url: "https://pub.dartlang.org"
227+
source: hosted
228+
version: "0.3.22+1"
161229
xdg_directories:
162230
dependency: transitive
163231
description:

js_api

js_as_extension/dist/index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<html>
2+
<body>
3+
<script src="main.js"></script>
4+
</body>
5+
</html>

js_as_extension/dist/main.js

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js_as_extension/package.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "@polkawallet/extension",
3+
"description": "A Polkawallet signer for the @polkadot/api",
4+
"version": "0.1.0-beta.1",
5+
"author": "Shawn Yang <[email protected]>",
6+
"license": "Apache-2",
7+
"scripts": {
8+
"clean": "rm -rf dist/*",
9+
"build": "webpack -p --mode production",
10+
"build-dev": "webpack -d --mode development"
11+
},
12+
"dependencies": {
13+
"@babel/polyfill": "^7.8.3",
14+
"@babel/runtime": "^7.11.2",
15+
"@polkadot/extension-base": "0.33.0-beta.2",
16+
"@polkadot/extension-dapp": "0.33.0-beta.2",
17+
"@polkadot/extension-inject": "0.33.0-beta.2"
18+
},
19+
"devDependencies": {
20+
"@polkadot/dev": "^0.55.34",
21+
"@babel/core": "^7.8.3",
22+
"@babel/preset-env": "^7.8.3",
23+
"@webpack-cli/info": "^0.2.0",
24+
"@webpack-cli/init": "^0.3.0",
25+
"babel-loader": "^8.0.6",
26+
"eslint": "^6.8.0",
27+
"eslint-config-prettier": "^6.9.0",
28+
"eslint-plugin-prettier": "^3.1.2",
29+
"prettier": "^1.19.1",
30+
"webpack": "^4.44.1",
31+
"webpack-cli": "^3.3.12"
32+
}
33+
}

0 commit comments

Comments
 (0)