Skip to content

Commit

Permalink
Fixed account not properly loading after unlock and loading of some a…
Browse files Browse the repository at this point in the history
…ccount based auths
  • Loading branch information
aaroncox committed Mar 28, 2022
1 parent a0fde43 commit c878085
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 9 deletions.
5 changes: 3 additions & 2 deletions app/modules/handler/actions/uri.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { find } from 'lodash';
import { get } from 'dot-prop-immutable';
import { Serialize } from 'eosjs2';
import { PrivateKey, Signature } from '@greymass/eosio';
import { PrivateKey, PublicKey, Signature } from '@greymass/eosio';

import * as types from '../../../shared/actions/types';
import eos from '../../../shared/actions/helpers/eos';
Expand Down Expand Up @@ -357,9 +357,10 @@ export function signIdentityRequest(
const signer = eos(networkConfig, true, true);
setTimeout(async () => {
try {
const requiredKeys = [String(PublicKey.from(wallet.pubkey))]
const signed = await signer.sign({
chainId: blockchain.chainId,
requiredKeys: [signer.convert(wallet.pubkey)],
requiredKeys,
serializedTransaction: prompt.resolved.serializedTransaction,
});
const callbackParams = prompt.resolved.getCallback(signed.signatures, 0);
Expand Down
10 changes: 8 additions & 2 deletions app/modules/handler/containers/Prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,15 @@ class PromptContainer extends Component<Props> {
}
};
swapAccount = (e, { value }) => {
const { actions } = this.props;
const { actions, wallets } = this.props;
const { blockchain } = this.state;
const wallet = pick(value, ['account', 'authorization', 'mode', 'path', 'pubkey']);
const wallet = pick(value, ['account', 'authorization', 'authAccount', 'authAuthorization', 'chainId', 'mode', 'path', 'pubkey']);
if (!wallet.pubkey && wallet.authAccount && wallet.authAuthorization) {
const authority = find(wallets, { chainId: wallet.chainId, account: wallet.authAccount, authorization: wallet.authAuthorization })
if (authority) {
wallet.pubkey = authority.pubkey
}
}
this.setState({
displayShareLink: initialState.displayShareLink,
enableWhitelist: initialState.enableWhitelist,
Expand Down
13 changes: 9 additions & 4 deletions app/modules/handler/containers/Stage.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ class PromptStage extends Component<Props> {
password,
blockchain.chainId,
// callback
() => actions.signURI(resolved.transaction, blockchain, wallet, broadcast, prompt.callback)
() => actions.signURI(resolved.transaction, blockchain, wallet, broadcast, prompt.callback),
wallet.authAccount,
wallet.authAuthorization
);
}
onUnlockAndSignIdentity= (password) => {
Expand All @@ -195,7 +197,9 @@ class PromptStage extends Component<Props> {
prompt,
blockchain,
wallet,
)
),
wallet.authAccount,
wallet.authAuthorization
);
}
render() {
Expand Down Expand Up @@ -264,8 +268,9 @@ class PromptStage extends Component<Props> {
([reqType] = prompt.req);
}


const hasWallet = !!(wallet.account && wallet.authorization && wallet.mode && wallet.pubkey);
const hasPublicKey = !!wallet.pubkey
const hasAccountAuth = !!(wallet.authAccount && wallet.authAuthorization)
const hasWallet = !!(wallet.account && wallet.authorization && wallet.mode && (hasPublicKey || hasAccountAuth));
const hasCallback = !!(prompt && prompt.callback);

const hasForegroundCallback = !!(
Expand Down
4 changes: 4 additions & 0 deletions app/modules/handler/containers/Stage/Identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class PromptStageIdentity extends Component<Props> {
const {
account,
authorization,
authAccount,
authAuthorization,
mode,
pubkey,
} = wallet;
Expand Down Expand Up @@ -99,6 +101,8 @@ class PromptStageIdentity extends Component<Props> {
<GlobalAccountDropdownSelect
account={account}
authorization={authorization}
authAccount={authAccount}
authAuthorization={authAuthorization}
mode={mode}
pubkey={pubkey}
chainId={chainId}
Expand Down
19 changes: 18 additions & 1 deletion app/shared/actions/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,15 @@ export function unlockWallet(password, useWallet = false, unlockAll = true) {
};
}

export function unlockWalletByAuth(account, authorization, password, chainId = false, callback = false) {
export function unlockWalletByAuth(
account,
authorization,
password,
chainId = false,
callback = false,
authAccount = false,
authAuthorization = false,
) {
return async (dispatch: () => void, getState) => {
const state = getState();
const {
Expand All @@ -306,6 +314,15 @@ export function unlockWalletByAuth(account, authorization, password, chainId = f
query.chainId = chainId;
}
const wallet = find(wallets, query);
// get the appropriate public key if this is account based auth
if (authAccount && authAuthorization) {
const authority = find(wallets, {
...query,
account: authAccount,
authorization: authAuthorization,
});
wallet.pubkey = authority.pubkey;
}

const accountData = accounts[wallet.account];
const blockchain = find(blockchains, { chainId: wallet.chainId });
Expand Down
4 changes: 4 additions & 0 deletions app/shared/containers/Global/Account/Dropdown/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class GlobalAccountDropdownSelect extends Component<Props> {
const {
account,
authorization,
authAccount,
authAuthorization,
chainId,
disabled,
fluid,
Expand All @@ -48,6 +50,8 @@ class GlobalAccountDropdownSelect extends Component<Props> {
<GlobalFragmentWallet
account={account}
authorization={authorization}
authAccount={authAccount}
authAuthorization={authAuthorization}
mode={mode}
pubkey={pubkey}
/>
Expand Down

0 comments on commit c878085

Please sign in to comment.