|
|
|
@ -1,4 +1,5 @@ |
|
|
|
import 'package:flutter/material.dart'; |
|
|
|
import 'package:flutter/material.dart'; |
|
|
|
|
|
|
|
import 'package:flutter/services.dart'; |
|
|
|
import 'package:provider/provider.dart'; |
|
|
|
import 'package:provider/provider.dart'; |
|
|
|
|
|
|
|
|
|
|
|
import 'package:esse/utils/adaptive.dart'; |
|
|
|
import 'package:esse/utils/adaptive.dart'; |
|
|
|
@ -20,17 +21,16 @@ class WalletDetail extends StatefulWidget { |
|
|
|
_WalletDetailState createState() => _WalletDetailState(); |
|
|
|
_WalletDetailState createState() => _WalletDetailState(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class Network { |
|
|
|
|
|
|
|
const Network(this.name, this.color); |
|
|
|
|
|
|
|
final Color color; |
|
|
|
|
|
|
|
final String name; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class _WalletDetailState extends State<WalletDetail> with SingleTickerProviderStateMixin { |
|
|
|
class _WalletDetailState extends State<WalletDetail> with SingleTickerProviderStateMixin { |
|
|
|
TabController? _tabController; |
|
|
|
TabController? _tabController; |
|
|
|
List<Address> _addresses = []; |
|
|
|
|
|
|
|
bool _needGenerate = false; |
|
|
|
bool _needGenerate = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<Address> _addresses = []; |
|
|
|
|
|
|
|
Address? _selectedAddress; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<Network> _networks = []; |
|
|
|
|
|
|
|
Network? _selectedNetwork; |
|
|
|
|
|
|
|
|
|
|
|
List tokens = [ |
|
|
|
List tokens = [ |
|
|
|
['ETH', '100', '1000', 'assets/logo/logo_eth.png'], |
|
|
|
['ETH', '100', '1000', 'assets/logo/logo_eth.png'], |
|
|
|
['USDT', '2000', '2000', 'assets/logo/logo_tether.png'], |
|
|
|
['USDT', '2000', '2000', 'assets/logo/logo_tether.png'], |
|
|
|
@ -38,36 +38,16 @@ class _WalletDetailState extends State<WalletDetail> with SingleTickerProviderSt |
|
|
|
['FFF', '100', '1000', 'assets/logo/logo_erc20.png'], |
|
|
|
['FFF', '100', '1000', 'assets/logo/logo_erc20.png'], |
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
Network? selectedNetwork; |
|
|
|
|
|
|
|
List<Network> networks = <Network>[ |
|
|
|
|
|
|
|
const Network( |
|
|
|
|
|
|
|
'Ethereum Mainnet', |
|
|
|
|
|
|
|
const Color(0xFF167F67) |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
const Network( |
|
|
|
|
|
|
|
'Ropsten Test Network', |
|
|
|
|
|
|
|
Colors.orange, |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
const Network( |
|
|
|
|
|
|
|
'Rinkeby Test Network', |
|
|
|
|
|
|
|
Colors.orange, |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
const Network( |
|
|
|
|
|
|
|
'Localhost 8545', |
|
|
|
|
|
|
|
const Color(0xFF6174FF), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
|
@override |
|
|
|
void initState() { |
|
|
|
void initState() { |
|
|
|
_tabController = new TabController(length: 2, vsync: this); |
|
|
|
_tabController = new TabController(length: 2, vsync: this); |
|
|
|
rpc.addListener('wallet-generate', _walletGenerate, false); |
|
|
|
rpc.addListener('wallet-generate', _walletGenerate, false); |
|
|
|
|
|
|
|
rpc.addListener('wallet-balance', _walletBalance, false); |
|
|
|
super.initState(); |
|
|
|
super.initState(); |
|
|
|
Future.delayed(Duration.zero, _load); |
|
|
|
Future.delayed(Duration.zero, _load); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_walletGenerate(List params) { |
|
|
|
_walletGenerate(List params) { |
|
|
|
print('aaaaaaaaaaaaaaaaaa'); |
|
|
|
|
|
|
|
final address = Address.fromList(params); |
|
|
|
final address = Address.fromList(params); |
|
|
|
bool isNew = true; |
|
|
|
bool isNew = true; |
|
|
|
this._addresses.forEach((addr) { |
|
|
|
this._addresses.forEach((addr) { |
|
|
|
@ -81,6 +61,10 @@ class _WalletDetailState extends State<WalletDetail> with SingleTickerProviderSt |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_walletBalance(List params) { |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_load() async { |
|
|
|
_load() async { |
|
|
|
final res = await httpPost(Global.httpRpc, 'wallet-list', []); |
|
|
|
final res = await httpPost(Global.httpRpc, 'wallet-list', []); |
|
|
|
if (res.isOk) { |
|
|
|
if (res.isOk) { |
|
|
|
@ -98,6 +82,14 @@ class _WalletDetailState extends State<WalletDetail> with SingleTickerProviderSt |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_changeAddress(Address address) { |
|
|
|
|
|
|
|
this._selectedAddress = address; |
|
|
|
|
|
|
|
this._networks = address.networks(); |
|
|
|
|
|
|
|
if (!this._networks.contains(this._selectedNetwork)) { |
|
|
|
|
|
|
|
this._selectedNetwork = this._networks[0]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
|
@override |
|
|
|
Widget build(BuildContext context) { |
|
|
|
Widget build(BuildContext context) { |
|
|
|
final color = Theme.of(context).colorScheme; |
|
|
|
final color = Theme.of(context).colorScheme; |
|
|
|
@ -135,55 +127,74 @@ class _WalletDetailState extends State<WalletDetail> with SingleTickerProviderSt |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this._selectedAddress == null) { |
|
|
|
|
|
|
|
_changeAddress(this._addresses[0]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return Scaffold( |
|
|
|
return Scaffold( |
|
|
|
appBar: AppBar( |
|
|
|
appBar: AppBar( |
|
|
|
title: DropdownButton<Network>( |
|
|
|
title: DropdownButton<Network>( |
|
|
|
icon: Container(), |
|
|
|
icon: Container(), |
|
|
|
underline: Container(), |
|
|
|
underline: Container(), |
|
|
|
hint: Text("Select network"), |
|
|
|
value: this._selectedNetwork, |
|
|
|
value: selectedNetwork, |
|
|
|
|
|
|
|
onChanged: (Network? value) { |
|
|
|
onChanged: (Network? value) { |
|
|
|
if (value != null) { |
|
|
|
if (value != null) { |
|
|
|
setState(() { |
|
|
|
setState(() { |
|
|
|
selectedNetwork = value; |
|
|
|
this._selectedNetwork = value; |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
items: networks.map((Network network) { |
|
|
|
items: this._networks.map((Network network) { |
|
|
|
|
|
|
|
final params = network.params(); |
|
|
|
return DropdownMenuItem<Network>( |
|
|
|
return DropdownMenuItem<Network>( |
|
|
|
value: network, |
|
|
|
value: network, |
|
|
|
child: Container( |
|
|
|
child: Container( |
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 6.0), |
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 6.0), |
|
|
|
decoration: BoxDecoration( |
|
|
|
decoration: BoxDecoration( |
|
|
|
border: Border.all(width: 1.0, color: network.color), |
|
|
|
border: Border.all(width: 1.0, color: params[1]), |
|
|
|
borderRadius: BorderRadius.circular(25.0) |
|
|
|
borderRadius: BorderRadius.circular(25.0) |
|
|
|
), |
|
|
|
), |
|
|
|
child: Row( |
|
|
|
child: Row( |
|
|
|
children: <Widget>[ |
|
|
|
children: <Widget>[ |
|
|
|
Icon(Icons.public, color: network.color, size: 18.0), |
|
|
|
Icon(Icons.public, color: params[1], size: 18.0), |
|
|
|
const SizedBox(width: 10), |
|
|
|
const SizedBox(width: 10), |
|
|
|
Text(network.name, style: TextStyle(color: network.color, fontSize: 14.0)), |
|
|
|
Text(params[0], style: TextStyle(color: params[1], fontSize: 14.0)), |
|
|
|
], |
|
|
|
], |
|
|
|
)), |
|
|
|
)), |
|
|
|
); |
|
|
|
); |
|
|
|
}).toList(), |
|
|
|
}).toList(), |
|
|
|
), |
|
|
|
), |
|
|
|
actions: [ |
|
|
|
actions: [ |
|
|
|
TextButton( |
|
|
|
Padding( |
|
|
|
onPressed: () { |
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 10.0), |
|
|
|
setState(() {}); |
|
|
|
child: DropdownButton<Address>( |
|
|
|
}, |
|
|
|
icon: Container(), |
|
|
|
child: Container( |
|
|
|
underline: Container(), |
|
|
|
margin: const EdgeInsets.symmetric(horizontal: 10.0), |
|
|
|
value: this._selectedAddress, |
|
|
|
width: 40.0, |
|
|
|
onChanged: (Address? value) { |
|
|
|
height: 40.0, |
|
|
|
if (value != null) { |
|
|
|
decoration: BoxDecoration( |
|
|
|
setState(() { |
|
|
|
color: color.surface, |
|
|
|
_changeAddress(value); |
|
|
|
borderRadius: BorderRadius.circular(25.0) |
|
|
|
}); |
|
|
|
), |
|
|
|
} |
|
|
|
child: Center(child: Text('A')) |
|
|
|
}, |
|
|
|
) |
|
|
|
items: this._addresses.map((Address addr) { |
|
|
|
), |
|
|
|
return DropdownMenuItem<Address>( |
|
|
|
|
|
|
|
value: addr, |
|
|
|
|
|
|
|
child: Container( |
|
|
|
|
|
|
|
margin: const EdgeInsets.symmetric(horizontal: 10.0), |
|
|
|
|
|
|
|
width: 40.0, |
|
|
|
|
|
|
|
height: 40.0, |
|
|
|
|
|
|
|
decoration: BoxDecoration( |
|
|
|
|
|
|
|
color: color.surface, |
|
|
|
|
|
|
|
borderRadius: BorderRadius.circular(25.0) |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
child: Center(child: Text(addr.icon())) |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
}).toList(), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
) |
|
|
|
] |
|
|
|
] |
|
|
|
), |
|
|
|
), |
|
|
|
body: Container( |
|
|
|
body: Container( |
|
|
|
@ -193,7 +204,7 @@ class _WalletDetailState extends State<WalletDetail> with SingleTickerProviderSt |
|
|
|
children:[ |
|
|
|
children:[ |
|
|
|
InkWell( |
|
|
|
InkWell( |
|
|
|
onTap: () { |
|
|
|
onTap: () { |
|
|
|
//Clipboard.setData(ClipboardData(text: gidText(widget.id))); |
|
|
|
Clipboard.setData(ClipboardData(text: this._selectedAddress!.address)); |
|
|
|
}, |
|
|
|
}, |
|
|
|
child: Container( |
|
|
|
child: Container( |
|
|
|
padding: const EdgeInsets.symmetric(vertical: 10.0), |
|
|
|
padding: const EdgeInsets.symmetric(vertical: 10.0), |
|
|
|
@ -204,12 +215,13 @@ class _WalletDetailState extends State<WalletDetail> with SingleTickerProviderSt |
|
|
|
child: Column( |
|
|
|
child: Column( |
|
|
|
mainAxisAlignment: MainAxisAlignment.center, |
|
|
|
mainAxisAlignment: MainAxisAlignment.center, |
|
|
|
children: [ |
|
|
|
children: [ |
|
|
|
Text('Account1', style: TextStyle(fontSize: 18.0)), |
|
|
|
Text(this._selectedAddress!.name, style: TextStyle(fontSize: 18.0)), |
|
|
|
const SizedBox(height: 4.0), |
|
|
|
const SizedBox(height: 4.0), |
|
|
|
Row( |
|
|
|
Row( |
|
|
|
mainAxisAlignment: MainAxisAlignment.center, |
|
|
|
mainAxisAlignment: MainAxisAlignment.center, |
|
|
|
children: [ |
|
|
|
children: [ |
|
|
|
Text('0x222...334444', style: TextStyle(color: Color(0xFFADB0BB))), |
|
|
|
Text(this._selectedAddress!.short(), |
|
|
|
|
|
|
|
style: TextStyle(color: Color(0xFFADB0BB))), |
|
|
|
const SizedBox(width: 8.0), |
|
|
|
const SizedBox(width: 8.0), |
|
|
|
Icon(Icons.copy, size: 16.0, color: color.primary), |
|
|
|
Icon(Icons.copy, size: 16.0, color: color.primary), |
|
|
|
] |
|
|
|
] |
|
|
|
|