| 1 | // import 'dart:typed_data'; |
| 2 | // |
| 3 | // import 'package:basic_utils/basic_utils.dart'; |
| 4 | // import 'package:bitcoin_base/bitcoin_base.dart'; |
| 5 | // import 'package:cake_wallet/src/screens/base_page.dart'; |
| 6 | // import 'package:cake_wallet/src/screens/connect_device/widgets/device_tile.dart'; |
| 7 | // import 'package:cake_wallet/src/widgets/primary_button.dart'; |
| 8 | // import 'package:cake_wallet/utils/responsive_layout_util.dart'; |
| 9 | // import 'package:flutter/material.dart'; |
| 10 | // import 'package:ledger_flutter_plus/ledger_flutter_plus.dart'; |
| 11 | // import 'package:ledger_litecoin/ledger_litecoin.dart'; |
| 12 | // import 'package:permission_handler/permission_handler.dart'; |
| 13 | // |
| 14 | // class DebugDevicePage extends BasePage { |
| 15 | // @override |
| 16 | // String get title => "Connect Ledger"; |
| 17 | // |
| 18 | // @override |
| 19 | // Widget body(BuildContext context) => DebugDevicePageBody(); |
| 20 | // } |
| 21 | // |
| 22 | // class DebugDevicePageBody extends StatefulWidget { |
| 23 | // @override |
| 24 | // DebugDevicePageBodyState createState() => DebugDevicePageBodyState(); |
| 25 | // } |
| 26 | // |
| 27 | // class DebugDevicePageBodyState extends State<DebugDevicePageBody> { |
| 28 | // final imageLedger = Image.asset( |
| 29 | // 'assets/images/ledger_icon_black.png', |
| 30 | // width: 40, |
| 31 | // ); |
| 32 | // final ledger = Ledger( |
| 33 | // options: LedgerOptions( |
| 34 | // scanMode: ScanMode.balanced, |
| 35 | // maxScanDuration: const Duration(milliseconds: 5000), |
| 36 | // ), |
| 37 | // onPermissionRequest: (status) async { |
| 38 | // Map<Permission, PermissionStatus> statuses = await [ |
| 39 | // // Permission.location, |
| 40 | // Permission.bluetoothScan, |
| 41 | // Permission.bluetoothConnect, |
| 42 | // Permission.bluetoothAdvertise, |
| 43 | // ].request(); |
| 44 | // |
| 45 | // if (status != BleStatus.ready) { |
| 46 | // return false; |
| 47 | // } |
| 48 | // |
| 49 | // return statuses.values.where((status) => status.isDenied).isEmpty; |
| 50 | // }, |
| 51 | // ); |
| 52 | // |
| 53 | // // late BitcoinLedgerApp btc; |
| 54 | // late LitecoinLedgerApp ltc; |
| 55 | // |
| 56 | // var devices = <LedgerDevice>[]; |
| 57 | // var status = ""; |
| 58 | // var counter = 0; |
| 59 | // LedgerDevice? selectedDevice = null; |
| 60 | // |
| 61 | // @override |
| 62 | // void initState() { |
| 63 | // super.initState(); |
| 64 | // // btc = BitcoinLedgerApp(ledger); |
| 65 | // ltc = LitecoinLedgerApp(ledger); |
| 66 | // } |
| 67 | // |
| 68 | // @override |
| 69 | // void dispose() { |
| 70 | // super.dispose(); |
| 71 | // ledger.close(ConnectionType.ble); |
| 72 | // ledger.close(ConnectionType.usb); |
| 73 | // } |
| 74 | // |
| 75 | // Future<void> reconnectCurrentDevice() async { |
| 76 | // // await ledger.disconnect(selectedDevice!); |
| 77 | // // await ledger.connect(selectedDevice!); |
| 78 | // } |
| 79 | // |
| 80 | // Future<void> disconnectCurrentDevice() async { |
| 81 | // await ledger.disconnect(selectedDevice!); |
| 82 | // setState(() => selectedDevice = null); |
| 83 | // } |
| 84 | // |
| 85 | // @override |
| 86 | // Widget build(BuildContext context) { |
| 87 | // final imageLedger = 'assets/images/hardware_wallet/ledger_nano_x.png'; |
| 88 | // |
| 89 | // return Center( |
| 90 | // child: Container( |
| 91 | // width: ResponsiveLayoutUtilBase.kDesktopMaxWidthConstraint, |
| 92 | // height: double.infinity, |
| 93 | // padding: EdgeInsets.symmetric(vertical: 24, horizontal: 24), |
| 94 | // child: SingleChildScrollView( |
| 95 | // child: Column( |
| 96 | // children: [ |
| 97 | // Padding( |
| 98 | // padding: EdgeInsets.only(top: 20), |
| 99 | // child: Text(status), |
| 100 | // ), |
| 101 | // if (selectedDevice != null) ...[ |
| 102 | // DebugButton( |
| 103 | // title: "Get Version", |
| 104 | // method: "Version", |
| 105 | // // func: () async => await btc.getVersion(selectedDevice!), |
| 106 | // func: () async => await ltc.getVersion(selectedDevice!), |
| 107 | // ), |
| 108 | // DebugButton( |
| 109 | // title: "Get Wallet Address", |
| 110 | // method: "Wallet Address", |
| 111 | // func: () async { |
| 112 | // setState(() => counter++); |
| 113 | // final derivationPath = "m/84'/2'/0'/0/0"; |
| 114 | // return await ltc.getAccounts(selectedDevice!, |
| 115 | // accountsDerivationPath: derivationPath); |
| 116 | // // return await btc.getAccounts(selectedDevice!, accountsDerivationPath: derivationPath); |
| 117 | // // return await ethereum!.getHardwareWalletAccounts(selectedDevice!); |
| 118 | // }, |
| 119 | // ), |
| 120 | // DebugButton( |
| 121 | // title: "Send Money", |
| 122 | // method: "Raw Tx", |
| 123 | // func: sendMoney |
| 124 | // ), |
| 125 | // Padding( |
| 126 | // padding: EdgeInsets.only(top: 20), |
| 127 | // child: PrimaryButton( |
| 128 | // text: "Disconnect", |
| 129 | // onPressed: () => disconnectCurrentDevice(), |
| 130 | // color: Theme.of(context).colorScheme.primary, |
| 131 | // textColor: Theme.of(context).colorScheme.onPrimary), |
| 132 | // ), |
| 133 | // ], |
| 134 | // if (selectedDevice == null) ...[ |
| 135 | // ...devices |
| 136 | // .map( |
| 137 | // (device) => Padding( |
| 138 | // padding: EdgeInsets.only(bottom: 20), |
| 139 | // child: DeviceTile( |
| 140 | // onPressed: () { |
| 141 | // setState(() => selectedDevice = device); |
| 142 | // ledger.connect(device); |
| 143 | // }, |
| 144 | // title: device.name, |
| 145 | // leading: imageLedger, |
| 146 | // connectionType: device.connectionType, |
| 147 | // ), |
| 148 | // ), |
| 149 | // ) |
| 150 | // .toList(), |
| 151 | // PrimaryButton( |
| 152 | // text: "Refresh BLE", |
| 153 | // onPressed: () async { |
| 154 | // setState(() => devices = []); |
| 155 | // ledger.scan().listen((device) => setState(() { |
| 156 | // devices.add(device); |
| 157 | // })); |
| 158 | // }, |
| 159 | // color: Theme.of(context).colorScheme.primary, |
| 160 | // textColor: Theme.of(context).colorScheme.onPrimary), |
| 161 | // Padding( |
| 162 | // padding: EdgeInsets.only(top: 20), |
| 163 | // child: PrimaryButton( |
| 164 | // text: "Use USB", |
| 165 | // onPressed: () async { |
| 166 | // final dev = await ledger.listUsbDevices(); |
| 167 | // setState(() => devices = dev); |
| 168 | // }, |
| 169 | // color: Theme.of(context).colorScheme.primary, |
| 170 | // textColor: Theme.of(context).colorScheme.onPrimary), |
| 171 | // ), |
| 172 | // ], |
| 173 | // ], |
| 174 | // ), |
| 175 | // )), |
| 176 | // ); |
| 177 | // } |
| 178 | // |
| 179 | // Future<String> sendMoney() async { |
| 180 | // final readyInputs = [ |
| 181 | // LedgerTransaction( |
| 182 | // rawTx: "010000000001018c055c85c3724c98842d27712771dd0de139711f5940bba2df4615c5522184740000000017160014faf7f6dfb4e70798b92c93f33b4c51024491829df0ffffff022b05c70000000000160014f489f947fd13a1fb44ac168427081d3f30b6ce0cde9dd82e0000000017a914d5eca376cb49d65031220ff9093b7d407073ed0d8702483045022100f648c9f6a9b8f35b6ec29bbfae312c95ed3d56ce6a3f177d994efe90562ec4bd02205b82ce2c94bc0c9d152c3afc668b200bd82f48d6a14e83c66ba0f154cd5f69190121038f1dca119420d4aa7ad04af1c0d65304723789cccc56d335b18692390437f35900000000", |
| 183 | // outputIndex: 0, |
| 184 | // ownerPublicKey: |
| 185 | // HexUtils.decode("03b2e67958ed3356e329e05cf94c3bee6b20c17175ac3b2a1278e073bf44f5d6ec"), |
| 186 | // ownerDerivationPath: "m/84'/2'/0'/0/0", |
| 187 | // sequence: 0xffffffff, |
| 188 | // ) |
| 189 | // ]; |
| 190 | // |
| 191 | // final outputs = [ |
| 192 | // BitcoinOutput( |
| 193 | // address: P2wpkhAddress.fromAddress( |
| 194 | // address: "ltc1qn0g5e36xaj07lqj6w9xn52ng07hud42g3jf5ps", |
| 195 | // network: LitecoinNetwork.mainnet), |
| 196 | // value: BigInt.from(1000000)), |
| 197 | // BitcoinOutput( |
| 198 | // address: P2wpkhAddress.fromAddress( |
| 199 | // address: "ltc1qrx29qz4ghu4j0xk37ptgk7034cwpmjyxhrcnk9", |
| 200 | // network: LitecoinNetwork.mainnet), |
| 201 | // value: BigInt.from(12042705)), |
| 202 | // ]; |
| 203 | // return await ltc.createTransaction(selectedDevice!, |
| 204 | // inputs: readyInputs, |
| 205 | // outputs: outputs |
| 206 | // .map((e) => TransactionOutput.fromBigInt( |
| 207 | // e.value, Uint8List.fromList(e.address.toScriptPubKey().toBytes()))) |
| 208 | // .toList(), |
| 209 | // sigHashType: 0x01, |
| 210 | // additionals: ["bech32"], |
| 211 | // isSegWit: true, |
| 212 | // useTrustedInputForSegwit: true); |
| 213 | // } |
| 214 | // |
| 215 | // Widget DebugButton( |
| 216 | // {required String title, required String method, required Future<dynamic> Function() func}) { |
| 217 | // return Padding( |
| 218 | // padding: EdgeInsets.only(top: 20), |
| 219 | // child: PrimaryButton( |
| 220 | // text: title, |
| 221 | // onPressed: () async { |
| 222 | // try { |
| 223 | // setState(() => status = "Sending..."); |
| 224 | // final acc = await func(); |
| 225 | // setState(() => status = "$method: $acc"); |
| 226 | // printV("$method: $acc"); |
| 227 | // } on LedgerException catch (ex) { |
| 228 | // setState(() => status = "${ex.errorCode.toRadixString(16)} ${ex.message}"); |
| 229 | // printV("${ex.errorCode.toRadixString(16)} ${ex.message}"); |
| 230 | // } |
| 231 | // }, |
| 232 | // color: Theme.of(context).colorScheme.primary, |
| 233 | // textColor: Theme.of(context).colorScheme.onPrimary), |
| 234 | // ); |
| 235 | // } |
| 236 | // } |