1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 01:47:00 +01:00

[MMI] Adding missing logic to handle custodian approval in token allowance (#20662)

This commit is contained in:
Albert Olivé 2023-08-31 17:45:07 +02:00 committed by GitHub
parent ec0a02fe40
commit 3376ea4e95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 20 deletions

View File

@ -641,9 +641,10 @@ export default class MMIController extends EventEmitter {
async setAccountAndNetwork(origin, address, chainId) { async setAccountAndNetwork(origin, address, chainId) {
await this.appStateController.getUnlockPromise(true); await this.appStateController.getUnlockPromise(true);
const addressToLowerCase = address.toLowerCase();
const selectedAddress = this.preferencesController.getSelectedAddress(); const selectedAddress = this.preferencesController.getSelectedAddress();
if (selectedAddress.toLowerCase() !== address.toLowerCase()) { if (selectedAddress.toLowerCase() !== addressToLowerCase) {
this.preferencesController.setSelectedAddress(address); this.preferencesController.setSelectedAddress(addressToLowerCase);
} }
const selectedChainId = parseInt( const selectedChainId = parseInt(
this.networkController.state.providerConfig.chainId, this.networkController.state.providerConfig.chainId,
@ -667,7 +668,7 @@ export default class MMIController extends EventEmitter {
getPermissionBackgroundApiMethods( getPermissionBackgroundApiMethods(
this.permissionController, this.permissionController,
).addPermittedAccount(origin, address); ).addPermittedAccount(origin, addressToLowerCase);
return true; return true;
} }

View File

@ -176,7 +176,14 @@ export default function ConfirmApprove({
if (assetStandard === undefined) { if (assetStandard === undefined) {
return <ConfirmContractInteraction />; return <ConfirmContractInteraction />;
} }
if (assetStandard === TokenStandard.ERC20) {
let tokenAllowanceImprovements = true;
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
tokenAllowanceImprovements = false;
///: END:ONLY_INCLUDE_IN
if (tokenAllowanceImprovements && assetStandard === TokenStandard.ERC20) {
return ( return (
<GasFeeContextProvider transaction={transaction}> <GasFeeContextProvider transaction={transaction}>
<TransactionModalContextProvider> <TransactionModalContextProvider>
@ -224,6 +231,7 @@ export default function ConfirmApprove({
</GasFeeContextProvider> </GasFeeContextProvider>
); );
} }
return ( return (
<GasFeeContextProvider transaction={transaction}> <GasFeeContextProvider transaction={transaction}>
<ConfirmTransactionBase <ConfirmTransactionBase

View File

@ -52,27 +52,42 @@ export function getCustodianIconForAddress(state, address) {
} }
export function getIsCustodianSupportedChain(state) { export function getIsCustodianSupportedChain(state) {
const selectedIdentity = getSelectedIdentity(state); try {
const accountType = getAccountType(state); const selectedIdentity = getSelectedIdentity(state);
const providerConfig = getProviderConfig(state); const accountType = getAccountType(state);
const providerConfig = getProviderConfig(state);
const supportedChains = if (!selectedIdentity || !accountType || !providerConfig) {
accountType === 'custody' throw new Error('Invalid state');
? getCustodyAccountSupportedChains(state, selectedIdentity.address) }
: null;
return supportedChains?.supportedChains if (accountType !== 'custody') {
? supportedChains.supportedChains.includes( return true;
hexToDecimal(providerConfig.chainId), }
)
: true; const supportedChains = getCustodyAccountSupportedChains(
state,
selectedIdentity.address,
);
if (!supportedChains || !supportedChains.supportedChains) {
return true;
}
return supportedChains.supportedChains.includes(
hexToDecimal(providerConfig.chainId),
);
} catch (error) {
console.error(error);
throw error;
}
} }
export function getMMIAddressFromModalOrAddress(state) { export function getMMIAddressFromModalOrAddress(state) {
return ( const modalAddress = state?.appState?.modal?.modalState?.props?.address;
state.appState.modal.modalState.props.address || const selectedAddress = state?.metamask?.selectedAddress;
state.metamask.selectedAddress
); return modalAddress || selectedAddress;
} }
export function getMMIConfiguration(state) { export function getMMIConfiguration(state) {