feat: Change short pubkey format

This commit is contained in:
poka 2022-05-28 00:17:50 +02:00
parent 2a4b54d9eb
commit 104d00ff7e
8 changed files with 12 additions and 65 deletions

View File

@ -1,7 +1,5 @@
// ignore_for_file: avoid_print
import 'package:crypto/crypto.dart';
import 'package:fast_base58/fast_base58.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:gecko/globals.dart';
@ -54,7 +52,6 @@ class SubstrateSdk with ChangeNotifier {
n.ss58 = ss58;
node.add(n);
}
int timeout = 10000;
// if (n.endpoint!.startsWith('ws://')) {
@ -520,18 +517,10 @@ void snackNode(BuildContext context, bool isConnected) {
}
String getShortPubkey(String pubkey) {
List<int> pubkeyByte = Base58Decode(pubkey);
Digest pubkeyS256 = sha256.convert(sha256.convert(pubkeyByte).bytes);
String pubkeyCheksum = Base58Encode(pubkeyS256.bytes);
String pubkeyChecksumShort =
truncate(pubkeyCheksum, 3, omission: "", position: TruncatePosition.end);
String pubkeyShort = truncate(pubkey, 5,
String pubkeyShort = truncate(pubkey, 7,
omission: String.fromCharCode(0x2026),
position: TruncatePosition.end) +
truncate(pubkey, 4, omission: "", position: TruncatePosition.start) +
':$pubkeyChecksumShort';
truncate(pubkey, 6, omission: "", position: TruncatePosition.start);
return pubkeyShort;
}

View File

@ -1,6 +1,4 @@
import 'dart:io';
import 'package:crypto/crypto.dart';
import 'package:fast_base58/fast_base58.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:gecko/globals.dart';
@ -9,7 +7,6 @@ import 'package:gecko/models/wallet_data.dart';
import 'package:gecko/providers/substrate_sdk.dart';
import 'package:image_picker/image_picker.dart';
import 'package:provider/provider.dart';
import 'package:truncate/truncate.dart';
class WalletOptionsProvider with ChangeNotifier {
TextEditingController address = TextEditingController();
@ -108,22 +105,6 @@ class WalletOptionsProvider with ChangeNotifier {
);
}
String getShortPubkey(String pubkey) {
List<int> pubkeyByte = Base58Decode(pubkey);
Digest pubkeyS256 = sha256.convert(sha256.convert(pubkeyByte).bytes);
String pubkeyCheksum = Base58Encode(pubkeyS256.bytes);
String pubkeyChecksumShort = truncate(pubkeyCheksum, 3,
omission: "", position: TruncatePosition.end);
String pubkeyShort = truncate(pubkey, 5,
omission: String.fromCharCode(0x2026),
position: TruncatePosition.end) +
truncate(pubkey, 4, omission: "", position: TruncatePosition.start) +
':$pubkeyChecksumShort';
return pubkeyShort;
}
void bluringBalance() {
isBalanceBlur = !isBalanceBlur;
notifyListeners();

View File

@ -1,6 +1,7 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:gecko/globals.dart';
import 'package:gecko/providers/substrate_sdk.dart';
import 'package:gecko/screens/wallet_view.dart';
import 'package:graphql_flutter/graphql_flutter.dart';
import 'package:jdenticon_dart/jdenticon_dart.dart';
@ -8,9 +9,6 @@ import 'package:permission_handler/permission_handler.dart';
import 'package:qrscan/qrscan.dart' as scanner;
import 'dart:math';
import 'package:intl/intl.dart';
import 'package:truncate/truncate.dart';
import 'package:crypto/crypto.dart';
import 'package:fast_base58/fast_base58.dart';
class WalletsProfilesProvider with ChangeNotifier {
WalletsProfilesProvider(this.pubkey);
@ -105,23 +103,6 @@ class WalletsProfilesProvider with ChangeNotifier {
}
}
String getShortPubkey(String pubkey) {
// log.d(pubkey);
List<int> pubkeyByte = Base58Decode(pubkey);
Digest pubkeyS256 = sha256.convert(sha256.convert(pubkeyByte).bytes);
String pubkeyCheksum = Base58Encode(pubkeyS256.bytes);
String pubkeyChecksumShort = truncate(pubkeyCheksum, 3,
omission: "", position: TruncatePosition.end);
pubkeyShort = truncate(pubkey, 5,
omission: String.fromCharCode(0x2026),
position: TruncatePosition.end) +
truncate(pubkey, 4, omission: "", position: TruncatePosition.start) +
':$pubkeyChecksumShort';
return pubkeyShort;
}
// poka: Do99s6wQR2JLfhirPdpAERSjNbmjjECzGxHNJMiNKT3P
// Pi: D2meevcAHFTS2gQMvmRW5Hzi25jDdikk4nC4u1FkwRaU // For debug
// Boris: JE6mkuzSpT3ePciCPRTpuMT9fqPUVVLJz2618d33p7tn

View File

@ -2,6 +2,7 @@ import 'package:flutter/services.dart';
import 'package:gecko/globals.dart';
import 'package:gecko/providers/cesium_plus.dart';
import 'package:gecko/models/queries.dart';
import 'package:gecko/providers/substrate_sdk.dart';
import 'package:gecko/providers/wallets_profiles.dart';
import 'package:flutter/material.dart';
import 'package:gecko/screens/avatar_fullscreen.dart';
@ -406,7 +407,7 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
snackCopyKey(context);
},
child: Text(
_historyProvider.getShortPubkey(pubkey!),
getShortPubkey(pubkey!),
style: const TextStyle(
fontSize: 30,
fontWeight: FontWeight.w800,

View File

@ -239,8 +239,7 @@ class WalletOptions extends StatelessWidget {
}
Widget pubkeyWidget(WalletOptionsProvider walletProvider, BuildContext ctx) {
final String shortPubkey =
walletProvider.getShortPubkey(walletProvider.address.text);
final String shortPubkey = getShortPubkey(walletProvider.address.text);
return GestureDetector(
key: const Key('copyPubkey'),
onTap: () {
@ -256,17 +255,12 @@ class WalletOptions extends StatelessWidget {
height: 45,
),
const SizedBox(width: 20),
Text("${shortPubkey.split(':')[0]}:",
Text(shortPubkey,
style: const TextStyle(
fontSize: 22,
fontWeight: FontWeight.w800,
fontFamily: 'Monospace',
color: Colors.black)),
Text(shortPubkey.split(':')[1],
style: const TextStyle(
fontSize: 22,
fontWeight: FontWeight.w800,
fontFamily: 'Monospace')),
const SizedBox(width: 15),
SizedBox(
height: 40,

View File

@ -3,6 +3,7 @@ import 'package:gecko/globals.dart';
import 'package:flutter/material.dart';
import 'package:gecko/providers/cesium_plus.dart';
import 'package:gecko/models/g1_wallets_list.dart';
import 'package:gecko/providers/substrate_sdk.dart';
import 'package:gecko/providers/wallet_options.dart';
import 'package:gecko/providers/wallets_profiles.dart';
import 'package:gecko/providers/search.dart';
@ -126,8 +127,8 @@ class SearchResultScreen extends StatelessWidget {
}),
title: Row(children: <Widget>[
Text(
_walletsProfilesClass
.getShortPubkey(g1Wallet.pubkey!),
getShortPubkey(g1Wallet.pubkey!),
style: const TextStyle(
fontSize: 18,
fontFamily: 'Monospace',

View File

@ -31,7 +31,7 @@ class TransactionInProgress extends StatelessWidget {
log.d(_walletViewProvider.pubkey!);
final from = _myWalletProvider.getDefaultWallet()!.name!;
final to = _walletViewProvider.getShortPubkey(_walletViewProvider.pubkey!);
final to = getShortPubkey(_walletViewProvider.pubkey!);
final amount = _walletViewProvider.payAmount.text;
String _actionName = '';

View File

@ -519,7 +519,7 @@ class WalletViewScreen extends StatelessWidget {
snackCopyKey(context);
},
child: Text(
_historyProvider.getShortPubkey(pubkey!),
getShortPubkey(pubkey!),
style: const TextStyle(
fontSize: 30,
fontWeight: FontWeight.w800,