Skip to content

Commit

Permalink
fix: minor bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
druiz0992 committed Dec 4, 2021
1 parent abb617c commit b5ebb7b
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 42 deletions.
2 changes: 1 addition & 1 deletion cli/lib/nf3.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ class Nf3 {
if (typeof window !== 'undefined') {
if (window.ethereum && this.ethereumSigningKey === '') {
this.web3 = new Web3(window.ethereum);
window.ethereum.send('eth_requestAccounts');
window.ethereum.request({ method: 'eth_accounts' });
} else {
// Metamask not available
throw new Error('No Web3 provider found');
Expand Down
6 changes: 5 additions & 1 deletion wallet/src/views/login/components/create-wallet.view.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ function CreateWalletModal({ modalEnable, handleClickOnImport, toggleModalEnable
<Grid>
<Grid.Column width={12}>
<Form.Field>
<TextArea value={mnemonic} style={{ minheight: 100 }} />
<TextArea
value={mnemonic}
onChange={event => setMnemonic(event.target.value.replace(/\s+/g, ' '))}
style={{ minheight: 100 }}
/>
</Form.Field>
</Grid.Column>
<Grid.Column width={4}>
Expand Down
10 changes: 7 additions & 3 deletions wallet/src/views/login/login.view.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ function Login({ login, onLoadWallet, onDeleteWallet, onLoadTokens }) {
}
await nf3.setzkpKeysFromMnemonic(mnemonic, DEFAULT_NF_ADDRESS_INDEX);
onLoadWallet(nf3);
onLoadTokens(tokens);
const tokenPool = Storage.tokensGet(nf3.zkpKeys.compressedPkd);
if (!tokenPool) {
onLoadTokens(tokens);
}
} catch (err) {
console.log('Failed', err);
setModalEnable(false);
Expand Down Expand Up @@ -115,8 +118,9 @@ function Login({ login, onLoadWallet, onDeleteWallet, onLoadTokens }) {
<Header
as="h1"
style={{
fontSize: '4em',
fontWeight: 'normal',
fontSize: '2.5em',
fontFamily: 'verdana',
fontWeight: 'bold',
marginBottom: 0,
marginTop: '3em',
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function FooterMenu() {
fontSize: '4em',
fontWeight: 'normal',
marginBottom: 0,
marginTop: '4em',
marginTop: '1em',
}}
/>
<Menu secondary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@ import { Button, Modal, Form, Icon, Input, Checkbox, Divider } from 'semantic-ui
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import * as Storage from '../../../../utils/lib/local-storage';
import tokensLoad from '../../../../store/token/token.thunks';
import tokens from '../../../../utils/tokens';

function AccountSettingsModal({ login, accountSettingsEnable, toggleAccountSettings }) {
function AccountSettingsModal({
login,
accountSettingsEnable,
toggleAccountSettings,
onLoadTokens,
}) {
if (typeof login.nf3 === 'undefined' || Object.keys(login.nf3).length === 0) {
return null;
}
Expand All @@ -14,6 +21,8 @@ function AccountSettingsModal({ login, accountSettingsEnable, toggleAccountSetti
const handleSubmit = async () => {
if (login.nf3.mnemonic.addressIndex !== addressIndex) {
login.nf3.setzkpKeysFromMnemonic('', addressIndex);
const tokenPool = Storage.tokensGet(login.nf3.zkpKeys.compressedPkd);
onLoadTokens(tokenPool || tokens);
}

if (clearLocalStorage) {
Expand Down Expand Up @@ -42,6 +51,20 @@ function AccountSettingsModal({ login, accountSettingsEnable, toggleAccountSetti
onChange={event => setAddressIndex(event.target.value)}
/>
</Form.Field>
<Form.Field>
<Input
label="Compressd Pkd"
type="text"
readOnly
value={login.nf3.zkpKeys.compressedPkd}
/>
</Form.Field>
<Form.Field>
<Input label="Pkd-x" type="text" readOnly value={login.nf3.zkpKeys.pkd[0]} />
</Form.Field>
<Form.Field>
<Input label="Pkd-y" type="text" readOnly value={login.nf3.zkpKeys.pkd[1]} />
</Form.Field>
<Divider />
<Form.Field>
<Checkbox
Expand All @@ -68,12 +91,15 @@ AccountSettingsModal.propTypes = {
login: PropTypes.object.isRequired,
accountSettingsEnable: PropTypes.bool.isRequired,
toggleAccountSettings: PropTypes.func.isRequired,
onLoadTokens: PropTypes.func.isRequired,
};

const mapStateToProps = state => ({
login: state.login,
});

const mapDispatchToProps = () => ({});
const mapDispatchToProps = dispatch => ({
onLoadTokens: newTokens => dispatch(tokensLoad(newTokens)),
});

export default connect(mapStateToProps, mapDispatchToProps)(AccountSettingsModal);
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,15 @@ function TransactionsModal({ token, login, transactions, onSubmitTx, onCancelTx
if (!/^0x([A-Fa-f0-9]{63,64})$/.test(value)) return setPkdY({ value: '', error });
setPkdY({ value, error: null });
}
if (key === 'PK-X') {
if (!/^0x([A-Fa-f0-9]{63,64})$/.test(value)) return setPkdX({ value: '', error });
setPkdX({ value, error: null });
}
if (transactions.txType === 'withdraw') {
if (!/^0x([A-Fa-f0-9]{40})$/.test(value)) return setPkdX({ value: '', error });
} else if (!/^0x([A-Fa-f0-9]{63,64})$/.test(value)) return setPkdX({ value: '', error });
return setPkdX({ value, error: null });
setPkdX({ value, error: null });
}
return null;
}

function validateTokenId(tokenInfo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,39 +127,34 @@ function WalletInfo({
<Table padded fixed selectable>
<Table.Header>
<Table.Row>
<Table.HeaderCell colSpan="4">
<Table.Cell>Account Address:</Table.Cell>
<Table.Cell id="wallet-info-cell-ethaddress"> {importedWallet()} </Table.Cell>
<Table.HeaderCell>Account Address:</Table.HeaderCell>
<Table.HeaderCell colSpan="3" id="wallet-info-cell-ethaddress">
{' '}
{importedWallet()}{' '}
</Table.HeaderCell>
<Table.HeaderCell colSpan="3">
<Table.Cell />
<Table.Cell />
<Table.Cell>
<Button
icon
labelPosition="left"
onClick={toggleModalTokenAdd}
primary
id="wallet-info-cell-add-token"
>
<Icon name="plus" />
Add Token
</Button>
</Table.Cell>
<Table.Cell>
<Button
icon
labelPosition="left"
id="wallet-info-cell-remove-token"
toggle
onClick={removeToken}
primary
active={removeTokenEnable && token.tokenPool.length}
disabled={token.tokenPool.length === 0}
>
<Icon name="minus" /> Remove Token
</Button>
</Table.Cell>
<Button
icon
labelPosition="left"
onClick={toggleModalTokenAdd}
primary
id="wallet-info-cell-add-token"
>
<Icon name="plus" />
Add Token
</Button>
<Button
icon
labelPosition="left"
id="wallet-info-cell-remove-token"
toggle
onClick={removeToken}
primary
active={removeTokenEnable && token.tokenPool.length}
disabled={token.tokenPool.length === 0}
>
<Icon name="minus" /> Remove Token
</Button>
</Table.HeaderCell>
</Table.Row>
</Table.Header>
Expand Down
2 changes: 1 addition & 1 deletion wallet/src/views/transactions/transactions.view.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function Transactions({ login }) {
<Header
as="h1"
style={{
fontSize: '2.7em',
fontSize: '2.5em',
fontFamily: 'verdana',
fontWeight: 'bold',
marginBottom: 0,
Expand Down

0 comments on commit b5ebb7b

Please sign in to comment.