Skip to content

Commit

Permalink
fix: wallet kind changes from zingolib applied
Browse files Browse the repository at this point in the history
  • Loading branch information
juanky201271 committed Oct 7, 2024
1 parent 679f813 commit e6e9167
Show file tree
Hide file tree
Showing 5 changed files with 201 additions and 157 deletions.
14 changes: 12 additions & 2 deletions app/LoadingApp/LoadingApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ import Launching from './Launching';
import simpleBiometrics from '../simpleBiometrics';
import selectingServer from '../selectingServer';
import { isEqual } from 'lodash';
import { RPCWalletKindEnum } from '../rpc/enums/RPCWalletKindEnum';
import { RestoreFromTypeEnum } from '../AppState';

// no lazy load because slowing down screens.
Expand All @@ -83,6 +82,7 @@ import Seed from '../../components/Seed';
import ImportUfvk from '../../components/Ufvk/ImportUfvk';
import ChainTypeToggle from '../../components/Components/ChainTypeToggle';
import { sendEmail } from '../sendEmail';
import { RPCWalletKindEnum } from '../rpc/enums/RPCWalletKindEnum';

const en = require('../translations/en.json');
const es = require('../translations/es.json');
Expand Down Expand Up @@ -489,8 +489,18 @@ export class LoadingAppClass extends Component<LoadingAppClassProps, LoadingAppC
//console.log(walletKindStr);
try {
const walletKindJSON: RPCWalletKindType = await JSON.parse(walletKindStr);
console.log(walletKindJSON);
// there are 4 kinds:
// 1. seed
// 2. USK
// 3. UFVK - watch-only wallet
// 4. No keys - watch-only wallet (possibly an error)
this.setState({
readOnly: walletKindJSON.kind === RPCWalletKindEnum.Seeded ? false : true,
readOnly:
walletKindJSON.kind === RPCWalletKindEnum.LoadedFromUnifiedFullViewingKey ||
walletKindJSON.kind === RPCWalletKindEnum.NoKeysFound
? true
: false,
actionButtonsDisabled: false,
});
} catch (e) {
Expand Down
10 changes: 8 additions & 2 deletions app/rpc/enums/RPCWalletKindEnum.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
export enum RPCWalletKindEnum {
Seeded = 'Seeded',
LoadedFromKey = 'Loaded from key',
LoadedFromSeedPhrase = 'Loaded from seed phrase',
LoadedFromUnifiedSpendingKey = 'Loaded from unified spending key',
LoadedFromUnifiedFullViewingKey = 'Loaded from unified full viewing key',
NoKeysFound = 'No keys found',

// obsolete
//Seeded = 'Seeded',
//LoadedFromKey = 'Loaded from key',
}
6 changes: 3 additions & 3 deletions app/rpc/types/RPCWalletKindType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { RPCWalletKindEnum } from '../enums/RPCWalletKindEnum';

export type RPCWalletKindType = {
kind: RPCWalletKindEnum;
transparent?: string;
sapling?: string;
orchard?: string;
transparent: boolean;
sapling: boolean;
orchard: boolean;
};
211 changes: 123 additions & 88 deletions components/Pools/Pools.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable react-native/no-inline-styles */
import React, { useContext, useEffect } from 'react';
import React, { useContext, useEffect, useState } from 'react';
import { View, ScrollView, SafeAreaView } from 'react-native';
import { useTheme } from '@react-navigation/native';

Expand All @@ -18,7 +18,9 @@ import moment from 'moment';
import 'moment/locale/es';
import 'moment/locale/pt';
import 'moment/locale/ru';
import { ButtonTypeEnum, GlobalConst } from '../../app/AppState';
import { ButtonTypeEnum, CommandEnum, GlobalConst } from '../../app/AppState';
import RPCModule from '../../app/RPCModule';
import { RPCWalletKindType } from '../../app/rpc/types/RPCWalletKindType';

type PoolsProps = {
closeModal: () => void;
Expand All @@ -29,11 +31,25 @@ const Pools: React.FunctionComponent<PoolsProps> = ({ closeModal, setPrivacyOpti
const context = useContext(ContextAppLoaded);
const { totalBalance, info, translate, privacy, addLastSnackbar, somePending, language } = context;
const { colors } = useTheme() as unknown as ThemeType;
const [orchardPool, setOrchardPool] = useState<boolean>(true);
const [saplingPool, setSaplingPool] = useState<boolean>(true);
const [transparentPool, setTransparentPool] = useState<boolean>(true);
moment.locale(language);

// because this screen is fired from more places than the menu.
useEffect(() => {
(async () => await RPC.rpcSetInterruptSyncAfterBatch(GlobalConst.false))();
(async () => {
// because this screen is fired from more places than the menu.
await RPC.rpcSetInterruptSyncAfterBatch(GlobalConst.false);
// checking the pools of this wallet
const walletKindStr: string = await RPCModule.execute(CommandEnum.walletKind, '');
try {
const walletKindJSON: RPCWalletKindType = await JSON.parse(walletKindStr);
console.log(walletKindJSON);
setOrchardPool(walletKindJSON.orchard);
setSaplingPool(walletKindJSON.sapling);
setTransparentPool(walletKindJSON.transparent);
} catch (e) {}
})();
}, []);

//console.log('render pools. Balance:', totalBalance);
Expand Down Expand Up @@ -64,94 +80,113 @@ const Pools: React.FunctionComponent<PoolsProps> = ({ closeModal, setPrivacyOpti
justifyContent: 'flex-start',
}}>
<View style={{ display: 'flex', margin: 20, marginBottom: 30 }}>
<BoldText>{translate('pools.orchard-title') as string}</BoldText>

{totalBalance && (
<>
<View style={{ display: 'flex', marginLeft: 25 }}>
<DetailLine label={translate('pools.orchard-balance') as string}>
<ZecAmount
testID="orchard-total-balance"
amtZec={totalBalance.orchardBal}
size={18}
currencyName={info.currencyName}
style={{
opacity:
totalBalance.spendableOrchard > 0 && totalBalance.spendableOrchard === totalBalance.orchardBal
? 1
: 0.5,
}}
privacy={privacy}
/>
</DetailLine>
<DetailLine label={translate('pools.orchard-spendable-balance') as string}>
<ZecAmount
testID="orchard-spendable-balance"
amtZec={totalBalance.spendableOrchard}
size={18}
currencyName={info.currencyName}
color={
totalBalance.spendableOrchard > 0 && totalBalance.spendableOrchard === totalBalance.orchardBal
? colors.primary
: 'red'
}
privacy={privacy}
/>
</DetailLine>
</View>

<View style={{ height: 1, width: '100%', backgroundColor: 'white', marginTop: 15, marginBottom: 10 }} />

<BoldText>{translate('pools.sapling-title') as string}</BoldText>

<View style={{ display: 'flex', marginLeft: 25 }}>
<DetailLine label={translate('pools.sapling-balance') as string}>
<ZecAmount
testID="sapling-total-balance"
amtZec={totalBalance.privateBal}
size={18}
currencyName={info.currencyName}
style={{
opacity:
totalBalance.spendablePrivate > 0 && totalBalance.spendablePrivate === totalBalance.privateBal
? 1
: 0.5,
}}
privacy={privacy}
{orchardPool && (
<>
<BoldText>{translate('pools.orchard-title') as string}</BoldText>

<View style={{ display: 'flex', marginLeft: 25 }}>
<DetailLine label={translate('pools.orchard-balance') as string}>
<ZecAmount
testID="orchard-total-balance"
amtZec={totalBalance.orchardBal}
size={18}
currencyName={info.currencyName}
style={{
opacity:
totalBalance.spendableOrchard > 0 &&
totalBalance.spendableOrchard === totalBalance.orchardBal
? 1
: 0.5,
}}
privacy={privacy}
/>
</DetailLine>
<DetailLine label={translate('pools.orchard-spendable-balance') as string}>
<ZecAmount
testID="orchard-spendable-balance"
amtZec={totalBalance.spendableOrchard}
size={18}
currencyName={info.currencyName}
color={
totalBalance.spendableOrchard > 0 && totalBalance.spendableOrchard === totalBalance.orchardBal
? colors.primary
: 'red'
}
privacy={privacy}
/>
</DetailLine>
</View>

<View
style={{ height: 1, width: '100%', backgroundColor: 'white', marginTop: 15, marginBottom: 10 }}
/>
</DetailLine>
<DetailLine label={translate('pools.sapling-spendable-balance') as string}>
<ZecAmount
testID="sapling-spendable-balance"
amtZec={totalBalance.spendablePrivate}
size={18}
currencyName={info.currencyName}
color={
totalBalance.spendablePrivate > 0 && totalBalance.spendablePrivate === totalBalance.privateBal
? colors.syncing
: 'red'
}
privacy={privacy}
/>
</DetailLine>
</View>

<View style={{ height: 1, width: '100%', backgroundColor: 'white', marginTop: 15, marginBottom: 10 }} />

<BoldText>{translate('pools.transparent-title') as string}</BoldText>

<View style={{ display: 'flex', marginLeft: 25 }}>
<DetailLine label={translate('pools.transparent-balance') as string}>
<ZecAmount
testID="transparent-balance"
amtZec={totalBalance.transparentBal}
size={18}
currencyName={info.currencyName}
color={'red'}
privacy={privacy}
</>
)}

{saplingPool && (
<>
<BoldText>{translate('pools.sapling-title') as string}</BoldText>

<View style={{ display: 'flex', marginLeft: 25 }}>
<DetailLine label={translate('pools.sapling-balance') as string}>
<ZecAmount
testID="sapling-total-balance"
amtZec={totalBalance.privateBal}
size={18}
currencyName={info.currencyName}
style={{
opacity:
totalBalance.spendablePrivate > 0 &&
totalBalance.spendablePrivate === totalBalance.privateBal
? 1
: 0.5,
}}
privacy={privacy}
/>
</DetailLine>
<DetailLine label={translate('pools.sapling-spendable-balance') as string}>
<ZecAmount
testID="sapling-spendable-balance"
amtZec={totalBalance.spendablePrivate}
size={18}
currencyName={info.currencyName}
color={
totalBalance.spendablePrivate > 0 && totalBalance.spendablePrivate === totalBalance.privateBal
? colors.syncing
: 'red'
}
privacy={privacy}
/>
</DetailLine>
</View>

<View
style={{ height: 1, width: '100%', backgroundColor: 'white', marginTop: 15, marginBottom: 10 }}
/>
</DetailLine>
</View>
</>
)}

{transparentPool && (
<>
<BoldText>{translate('pools.transparent-title') as string}</BoldText>

<View style={{ display: 'flex', marginLeft: 25 }}>
<DetailLine label={translate('pools.transparent-balance') as string}>
<ZecAmount
testID="transparent-balance"
amtZec={totalBalance.transparentBal}
size={18}
currencyName={info.currencyName}
color={'red'}
privacy={privacy}
/>
</DetailLine>
</View>
</>
)}

{somePending && (
<View
style={{
Expand Down
Loading

0 comments on commit e6e9167

Please sign in to comment.