Skip to content

Commit

Permalink
Merge branch 'meta' into rc
Browse files Browse the repository at this point in the history
  • Loading branch information
br0ck-w00d committed Sep 18, 2024
2 parents 50e0d64 + 26d8cfb commit dc700ea
Show file tree
Hide file tree
Showing 13 changed files with 316 additions and 204 deletions.
6 changes: 3 additions & 3 deletions magic/lib/cubits/data/keys/cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ class KeysCubit extends UpdatableCubit<KeysState> {
//see(mnemonics);
//try {
// see('-----------------------------');
// see(master.derivationWallets.first.mnemonic);
// see(master.derivationWallets.first.roots(Blockchain.evrmoreMain));
// see(master.derivationWallets.first.roots(Blockchain.ravencoinMain));
// see(master.derivationWallets.last.mnemonic);
// see(master.derivationWallets.last.roots(Blockchain.evrmoreMain));
// see(master.derivationWallets.last.roots(Blockchain.ravencoinMain));
//} catch (e) {}
emit(KeysState(
xpubs: xpubs ?? state.xpubs,
Expand Down
54 changes: 26 additions & 28 deletions magic/lib/cubits/pane/receive/cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ class ReceiveCubit extends UpdatableCubit<ReceiveState> {
Blockchain blockchain, {
int? overrideIndex,
}) async {
if (cubits.keys.master.derivationWallets.first.cold) {
if (cubits.keys.master.derivationWallets.last.cold) {
final xpubs =
cubits.keys.master.derivationWallets.first.rootsMap(blockchain);
cubits.keys.master.derivationWallets.last.rootsMap(blockchain);
final index = overrideIndex ??
await _getIndex(
blockchain: blockchain,
exposure: Exposure.external,
derivationWallet: cubits.keys.master.derivationWallets.first,
derivationWallet: cubits.keys.master.derivationWallets.last,
overrideIndex: overrideIndex);
update(
address: blockchain.addressFromH160(
Expand All @@ -96,32 +96,30 @@ class ReceiveCubit extends UpdatableCubit<ReceiveState> {
return;
}
final seedWallet =
cubits.keys.master.derivationWallets.first.seedWallet(blockchain);
cubits.keys.master.derivationWallets.last.seedWallet(blockchain);
if (seedWallet.highestIndex.isEmpty) {
cubits.keys.master.derivationWallets.first.seedWallet(blockchain).derive({
cubits.keys.master.derivationWallets.last.seedWallet(blockchain).derive({
Exposure.internal: await _getIndex(
blockchain: blockchain,
exposure: Exposure.internal,
derivationWallet: cubits.keys.master.derivationWallets.first,
derivationWallet: cubits.keys.master.derivationWallets.last,
overrideIndex: overrideIndex),
Exposure.external: await _getIndex(
blockchain: blockchain,
exposure: Exposure.external,
derivationWallet: cubits.keys.master.derivationWallets.first,
derivationWallet: cubits.keys.master.derivationWallets.last,
overrideIndex: overrideIndex),
});
} else {
cubits.keys.master.derivationWallets.first
.seedWallet(blockchain)
.derive();
cubits.keys.master.derivationWallets.last.seedWallet(blockchain).derive();
}
update(
address: cubits.keys.master.derivationWallets.first
address: cubits.keys.master.derivationWallets.last
.seedWallet(blockchain)
.externals
.lastOrNull
?.address,
changeAddress: cubits.keys.master.derivationWallets.first
changeAddress: cubits.keys.master.derivationWallets.last
.seedWallet(blockchain)
.internals
.lastOrNull
Expand Down Expand Up @@ -168,36 +166,36 @@ class ReceiveCubit extends UpdatableCubit<ReceiveState> {
Blockchain blockchain, {
int? overrideIndex,
}) async {
if (cubits.keys.master.derivationWallets.first.cold) {
final xpub = cubits.keys.master.derivationWallets.first
if (cubits.keys.master.derivationWallets.last.cold) {
final xpub = cubits.keys.master.derivationWallets.last
.rootsMap(blockchain)[Exposure.external]!;
final index = overrideIndex ??
await _getIndex(
blockchain: blockchain,
exposure: Exposure.external,
derivationWallet: cubits.keys.master.derivationWallets.first,
derivationWallet: cubits.keys.master.derivationWallets.last,
overrideIndex: overrideIndex);
final address =
blockchain.addressFromH160(h160FromXPubForAddress(xpub, index));
update(address: address);
return;
}
final seedWallet =
cubits.keys.master.derivationWallets.first.seedWallet(blockchain);
cubits.keys.master.derivationWallets.last.seedWallet(blockchain);
if (seedWallet.highestIndex.isEmpty) {
cubits.keys.master.derivationWallets.first.seedWallet(blockchain).derive({
cubits.keys.master.derivationWallets.last.seedWallet(blockchain).derive({
Exposure.external: await _getIndex(
blockchain: blockchain,
exposure: Exposure.external,
derivationWallet: cubits.keys.master.derivationWallets.first,
derivationWallet: cubits.keys.master.derivationWallets.last,
overrideIndex: overrideIndex),
});
} else {
cubits.keys.master.derivationWallets.first
cubits.keys.master.derivationWallets.last
.seedWallet(blockchain)
.derive({Exposure.external: 0});
}
final addressFromSeed = cubits.keys.master.derivationWallets.first
final addressFromSeed = cubits.keys.master.derivationWallets.last
.seedWallet(blockchain)
.externals
.lastOrNull
Expand All @@ -209,37 +207,37 @@ class ReceiveCubit extends UpdatableCubit<ReceiveState> {
Blockchain blockchain, {
int? overrideIndex,
}) async {
if (cubits.keys.master.derivationWallets.first.cold) {
final xpub = cubits.keys.master.derivationWallets.first
if (cubits.keys.master.derivationWallets.last.cold) {
final xpub = cubits.keys.master.derivationWallets.last
.rootsMap(blockchain)[Exposure.internal]!;
final index = overrideIndex ??
await _getIndex(
blockchain: blockchain,
exposure: Exposure.internal,
derivationWallet: cubits.keys.master.derivationWallets.first,
derivationWallet: cubits.keys.master.derivationWallets.last,
overrideIndex: overrideIndex);
final address =
blockchain.addressFromH160(h160FromXPubForAddress(xpub, index));
update(changeAddress: address);
return address;
}
final seedWallet =
cubits.keys.master.derivationWallets.first.seedWallet(blockchain);
cubits.keys.master.derivationWallets.last.seedWallet(blockchain);
if (seedWallet.highestIndex.isEmpty) {
cubits.keys.master.derivationWallets.first.seedWallet(blockchain).derive({
cubits.keys.master.derivationWallets.last.seedWallet(blockchain).derive({
Exposure.internal: await _getIndex(
blockchain: blockchain,
exposure: Exposure.internal,
derivationWallet: cubits.keys.master.derivationWallets.first,
derivationWallet: cubits.keys.master.derivationWallets.last,
overrideIndex: overrideIndex),
});
} else {
cubits.keys.master.derivationWallets.first
cubits.keys.master.derivationWallets.last
.seedWallet(blockchain)
.derive({Exposure.internal: 0});
}
update(
changeAddress: cubits.keys.master.derivationWallets.first
changeAddress: cubits.keys.master.derivationWallets.last
.seedWallet(blockchain)
.internals
.last
Expand Down
15 changes: 13 additions & 2 deletions magic/lib/cubits/pane/wallet/cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ part 'state.dart';
class WalletCubit extends UpdatableCubit<WalletState> {
WalletCubit() : super(const WalletState());

DateTime populatedAt = DateTime.now();

List<Chips> defaultChips = [
Chips.all,
Chips.evrmore,
Expand Down Expand Up @@ -101,7 +103,12 @@ class WalletCubit extends UpdatableCubit<WalletState> {
update(holdings: [], active: true);
}

Future<bool> populateAssets() async {
Future<bool> populateAssets([int cooldown = 0]) async {
if (cooldown > 0 &&
DateTime.now().difference(populatedAt!).inSeconds < cooldown) {
return false;
}
populatedAt = DateTime.now();
// remember to order by currency first, amount second, alphabetical third
update(isSubmitting: true);
see('populateAssets');
Expand All @@ -121,7 +128,11 @@ class WalletCubit extends UpdatableCubit<WalletState> {
derivationWallets: cubits.keys.master.derivationWallets,
keypairWallets: cubits.keys.master.keypairWallets,
).call())));
update(holdings: holdings, isSubmitting: false);
see('holdings:', holdings, LogColors.magenta);
if (holdings.isNotEmpty) {
update(holdings: [], isSubmitting: false);
update(holdings: holdings, isSubmitting: false);
}
if (rates.rvnUsdRate != null) {
cacheRate(rates.rvnUsdRate!);
}
Expand Down
4 changes: 3 additions & 1 deletion magic/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ Future<void> main() async {
await cubits.keys.loadXPubs();
await cubits.menu.loadSettings();
// Initialize the Serverpod client with a retry mechanism to handle connection issues
print('setting up client');
await subscription.setupClient(FlutterConnectivityMonitor());
print('setted up client');
await precacheSvgPicture(LogoIcons.magic);

//ApiService.init();
Expand Down Expand Up @@ -141,7 +143,7 @@ Future<void> _clearAuthAndLoadKeys(BuildContext context) async {
/// TODO: rework to save at the root level.
await cubits.keys.loadXPubs();
////see(
//// cubits.keys.master.derivationWallets.first.roots(Blockchain.evrmoreMain));
//// cubits.keys.master.derivationWallets.last.roots(Blockchain.evrmoreMain));
////[xpub6EyL2KHeobgPS891ygwWVrZUAqRArjUk5Fs4zxQ9d6Yy1GMF78AULHZaRUNmg6BZzhPj7P6Qc6SXUGc4YHMV8A9wFcxw19tmNxnF1XfMHWZ, xpub6EyL2KHeobgPSohWN2j4xPiX5PFJvnbAi64u2yA3qDQTBcBd8jdN21jmvVsuTL8HDmyCN6cf7qaV3VbBR1DQeS7JFiq6JzRw6dToyLA4Qqq]
////[xpub6Djoyq41s3QGoGefbJCEkrdfHquk5315tdeuQMr21QxA3jSzGAxxLpqPfAz22RmmofBEx98MJf27KYyT8NN31SS6EzsiDxbYNDsv6hLBSfD, xpub6Djoyq41s3QGrA8YgAaZgdS3ALyG2vij5Fp1XSM9JRdx4kCrhWLtrifW67ncQhgWMmUQxRto3SS7zktvL81SxWwBtR63b9tLpDvc7ddrhHe]
subscription.ensureConnected().then((_) {
Expand Down
7 changes: 4 additions & 3 deletions magic/lib/presentation/ui/appbar/header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@ class Leading extends StatelessWidget {
onTap: state.onLead,
child: Container(
height: 16 + screen.iconMedium + 16,
width: 24 + screen.iconMedium,
width: 24 + screen.iconMedium + 8,
alignment: Alignment.centerRight,
color: Colors.transparent,
padding: const EdgeInsets.only(right: 8),
child: () {
if (state.leading == AppbarLeading.menu) {
return Icon(Icons.menu_rounded,
Expand Down Expand Up @@ -154,15 +155,15 @@ class Title extends StatelessWidget {
? state.titleChild
: (state.title == 'Magic'
? Padding(
padding: const EdgeInsets.only(left: 8, top: 8.0),
padding: const EdgeInsets.only(left: 0, top: 8.0),
child: SvgPicture.asset(
LogoIcons.magic,
height: screen.appbar.logoHeight,
fit: BoxFit.contain,
alignment: Alignment.center,
))
: Padding(
padding: const EdgeInsets.only(left: 16, top: 2.0),
padding: const EdgeInsets.only(left: 8, top: 2.0),
child: Text(state.title,
style: Theme.of(context)
.textTheme
Expand Down
12 changes: 11 additions & 1 deletion magic/lib/presentation/ui/canvas/holding/page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:flutter_svg/flutter_svg.dart';
import 'package:magic/cubits/canvas/holding/cubit.dart';
import 'package:magic/cubits/cubit.dart';
import 'package:magic/cubits/toast/cubit.dart';
import 'package:magic/domain/blockchain/blockchain.dart';
import 'package:magic/domain/concepts/holding.dart';
import 'package:magic/domain/concepts/numbers/coin.dart';
import 'package:magic/presentation/ui/pane/wallet/page.dart';
Expand All @@ -17,6 +18,10 @@ import 'package:magic/presentation/theme/theme.dart';
import 'package:magic/presentation/widgets/assets/icons.dart';
import 'package:magic/domain/concepts/asset_icons.dart';

Holding getHoldingOf(Blockchain blockchain) => cubits.wallet.state.holdings
.where((x) => x.blockchain == blockchain && x.isCurrency)
.first;

class HodingDetailPage extends StatelessWidget {
const HodingDetailPage({super.key});

Expand Down Expand Up @@ -133,7 +138,12 @@ class AnimatedCoinSpec extends StatelessWidget {
width: screen.width * .8,
child: Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [
const SizedBox.shrink(),
if (cubits.holding.state.holding.sats.value > 0)
if (cubits.holding.state.holding.sats.value > 0 &&
(cubits.holding.state.holding.isCurrency ||
getHoldingOf(cubits.holding.state.holding.blockchain)
.sats
.value >
0))
GestureDetector(
onTap:
//!['\$ -', '\$ 0.00'].contains(cubits.holding.state.usd)
Expand Down
Loading

0 comments on commit dc700ea

Please sign in to comment.