Skip to content

Commit ce5938c

Browse files
authored
Refactor1 (#3)
Refactored code Regenerated rust code Rust package update Regenerate polkadart Added unit test
1 parent 1c27478 commit ce5938c

82 files changed

Lines changed: 15803 additions & 268 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# Resonance Network Wallet
22

3-
A mobile wallet application for the Resonance Network blockchain and its native REZ cryptocurrency.
3+
A mobile wallet application for the Resonance Network blockchain and its native RES cryptocurrency.
44

55
## Features
66

77
- **Welcome Screen**: Create a new wallet or import an existing one
88
- **Create Wallet**: Generates a 24-word recovery phrase for a new wallet
99
- **Import Wallet**: Restore access using a 12 or 24-word recovery phrase
1010
- **Main Wallet Screen**: View balance and recent transactions
11-
- **Send REZ**: Send cryptocurrency to other accounts
12-
- **Receive REZ**: Display QR code with your wallet address
11+
- **Send RES**: Send cryptocurrency to other accounts
12+
- **Receive RES**: Display QR code with your wallet address
1313
- **Identity Support**: Display human-readable names for accounts when available
1414

1515
## Getting Started

generate_rust_bridge.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
flutter_rust_bridge_codegen generate

integration_test/simple_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ void main() {
77
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
88
setUpAll(() async => await RustLib.init());
99
testWidgets('Can call rust function', (WidgetTester tester) async {
10-
await tester.pumpWidget(const MyApp());
11-
expect(find.textContaining('Result: `Hello, Tom!`'), findsOneWidget);
10+
await tester.pumpWidget(const ResonanceWalletApp());
11+
expect(find.textContaining('Resonance Network'), findsOneWidget);
1212
});
1313
}

lib/account_profile.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'package:flutter/material.dart';
22
import 'package:flutter/services.dart';
3-
import 'substrate_service.dart';
3+
import 'package:resonance_network_wallet/core/services/substrate_service.dart';
44

55
class AccountProfilePage extends StatelessWidget {
66
final String accountId;
@@ -87,8 +87,7 @@ class AccountProfilePage extends StatelessWidget {
8787
onPressed: () {
8888
Clipboard.setData(ClipboardData(text: accountId));
8989
ScaffoldMessenger.of(context).showSnackBar(
90-
const SnackBar(
91-
content: Text('Address copied to clipboard')),
90+
const SnackBar(content: Text('Address copied to clipboard')),
9291
);
9392
},
9493
icon: const Icon(Icons.copy),
@@ -158,8 +157,7 @@ class AccountProfilePage extends StatelessWidget {
158157

159158
if (confirmed == true) {
160159
await SubstrateService().logout();
161-
Navigator.of(context)
162-
.pushNamedAndRemoveUntil('/', (route) => false);
160+
Navigator.of(context).pushNamedAndRemoveUntil('/', (route) => false);
163161
}
164162
},
165163
),
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class AppConstants {
2+
static const String appName = 'Resonance Network Wallet';
3+
static const String rpcEndpoint = 'ws://127.0.0.1:9944';
4+
5+
// Development accounts
6+
static const String crystalAlice = '//Crystal Alice';
7+
static const String crystalBob = '//Crystal Bob';
8+
static const String crystalCharlie = '//Crystal Charlie';
9+
10+
// Shared Preferences keys
11+
static const String hasWalletKey = 'has_wallet';
12+
static const String mnemonicKey = 'mnemonic';
13+
static const String accountIdKey = 'account_id';
14+
}
Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import 'dart:math';
66
import 'package:bip39/bip39.dart' as bip39;
77
import 'package:convert/convert.dart' as convert;
88

9-
import 'generated/resonance/resonance.dart';
10-
import 'generated/resonance/types/sp_runtime/multiaddress/multi_address.dart' as multi_address;
9+
import '../../generated/resonance/resonance.dart';
10+
import '../../generated/resonance/types/sp_runtime/multiaddress/multi_address.dart' as multi_address;
1111
import 'package:ss58/ss58.dart';
1212
import 'package:resonance_network_wallet/src/rust/api/crypto.dart' as crypto;
13-
import 'resonance_extrinsic_payload.dart';
13+
import '../../resonance_extrinsic_payload.dart';
1414

1515
class WalletInfo {
1616
final KeyPair keyPair;
@@ -82,10 +82,17 @@ class SubstrateService {
8282
static const String _rpcEndpoint = 'ws://127.0.0.1:9944'; // Replace with actual endpoint
8383

8484
Future<void> initialize() async {
85-
_provider = Provider.fromUri(Uri.parse(_rpcEndpoint));
86-
_stateApi = StateApi(_provider);
87-
_authorApi = AuthorApi(_provider);
88-
_systemApi = SystemApi(_provider);
85+
print('Initializing SubstrateService...');
86+
try {
87+
_provider = Provider.fromUri(Uri.parse(_rpcEndpoint));
88+
_stateApi = StateApi(_provider);
89+
_authorApi = AuthorApi(_provider);
90+
_systemApi = SystemApi(_provider);
91+
print('SubstrateService initialized successfully');
92+
} catch (e) {
93+
print('Error initializing SubstrateService: $e');
94+
rethrow;
95+
}
8996
}
9097

9198
String formatBalance(BigInt balance) {
@@ -159,22 +166,22 @@ class SubstrateService {
159166
}
160167

161168
Future<BigInt> queryBalance(String address) async {
169+
print('Querying balance for address: $address');
162170
try {
163171
// Create Resonance API instance
164172
final resonanceApi = Resonance(_provider);
165173
// Account from SS58 address
166174
final account = Address.decode(address);
167175

168-
// print('Account pubkey: ${account.pubkey}');
169-
170176
// Retrieve Account Balance
171177
final accountInfo = await resonanceApi.query.system.account(account.pubkey);
172-
// print('Balance for $address: ${accountInfo.data.free}');
178+
print('Balance for $address: ${accountInfo.data.free}');
173179

174180
// Get the free balance
175181
return accountInfo.data.free;
176-
} catch (e) {
182+
} catch (e, stackTrace) {
177183
print('Error querying balance: $e');
184+
print('Stack trace: $stackTrace');
178185
throw Exception('Failed to query balance: $e');
179186
}
180187
}
@@ -192,22 +199,30 @@ class SubstrateService {
192199
}
193200

194201
crypto.Keypair dilithiumKeypairFromMnemonic(String senderSeed) {
202+
print('Generating dilithium keypair from seed: $senderSeed');
195203
crypto.Keypair senderWallet;
196204
if (senderSeed.startsWith('//')) {
205+
print('Using development account path');
197206
switch (senderSeed) {
198207
case CRYSTAL_ALICE:
208+
print('Generating Crystal Alice keypair');
199209
senderWallet = crypto.crystalAlice();
210+
print('Crystal Alice public key: ${senderWallet.publicKey}');
211+
print('Crystal Alice address: ${senderWallet.ss58Address}');
200212
break;
201213
case CRYSTAL_BOB:
214+
print('Generating Crystal Bob keypair');
202215
senderWallet = crypto.crystalBob();
203216
break;
204217
case CRYSTAL_CHARLIE:
218+
print('Generating Crystal Charlie keypair');
205219
senderWallet = crypto.crystalCharlie();
206220
break;
207221
default:
208222
throw Exception('Invalid sender seed: $senderSeed');
209223
}
210224
} else {
225+
print('Using regular mnemonic');
211226
// Get the sender's wallet
212227
senderWallet = crypto.generateKeypair(mnemonicStr: senderSeed);
213228
}

0 commit comments

Comments
 (0)