Skip to content

Commit

Permalink
fix(merge): merge with main
Browse files Browse the repository at this point in the history
main sync
  • Loading branch information
zone-live committed Nov 7, 2023
2 parents 44d0165 + ce4769b commit 6111794
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 223 deletions.
2 changes: 1 addition & 1 deletion packages/custodyKeyring/src/CustodyKeyring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ export abstract class CustodyKeyring extends EventEmitter {
const normalisedSupportedChainIds = supportedChainIds.map(chainId => Number(chainId).toString());

if (!normalisedSupportedChainIds.includes(chainId)) {
throw new Error(`This network ${chainId} is not supported by ${this.custodianType.name}`);
throw new Error(`This network ${chainId} is not configured or supported with your custody provider.`);
}

let payload: IEIP1559TxParams | ILegacyTXParams;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ describe("CustodyKeyring", () => {
} as unknown as MetamaskTransaction;

await expect(custodyKeyring.signTransaction(fromAddress, ethTx, txMeta)).rejects.toThrowError(
"This network 777 is not supported by Jupiter",
"This network 777 is not configured or supported with your custody provider.",
);
});

Expand Down
110 changes: 0 additions & 110 deletions packages/extension/src/ExtensionSelectors.test.ts

This file was deleted.

48 changes: 0 additions & 48 deletions packages/extension/src/ExtensionSelectors.ts

This file was deleted.

17 changes: 7 additions & 10 deletions packages/extension/src/ExtensionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,34 +295,32 @@ export async function handleTxStatusUpdate(
};
txMeta.txParams = newTxParams;
}

// Sometimes custodians do not send a webhook when a transaction is submitted -
// They may only send one when the TX is confirmed (e.g. Safe) so we need to handle
// submission the same as confirmation

// Metamask resolves the promise in transaction controller when the TX is submitted
// So we can yield control back to that function as early as we can
// So we can yield control back to that function as early as we can

/**
* Previously, we were waiting for transaction confirmation from custodians before yielding
/**
* Previously, we were waiting for transaction confirmation from custodians before yielding
* We are now yielding on submission
* This has two effects
* 1. Interaction is yieled by MMI back to the dapp before confirmation, meaning it is much quicker
* 2. On-chain failures do not cause the dapp's RPC promise to be rejected, which is more in line with MetaMask's behaviour
* */

* */

if (
txData.transaction.status.submitted ||
(txData.transaction.status.finished &&
txData.transaction.status.success &&
txMeta.status !== MetaMaskTransactionStatuses.CONFIRMED)
txData.transaction.status.success &&
txMeta.status !== MetaMaskTransactionStatuses.CONFIRMED)
) {
// We don't need to wait for the custodian to confirm the TX, since MM's internal
// block tracker will do that for us

txStateManager.setTxStatusSubmitted(txMeta.id);

} else if (txData.transaction.status.finished && !txData.transaction.status.success) {
let message = `Transaction status from custodian: ${txMeta.custodyStatusDisplayText}`; // Clever English language hack IMO

Expand All @@ -338,4 +336,3 @@ export async function handleTxStatusUpdate(
}
return null;
}

16 changes: 1 addition & 15 deletions packages/extension/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
export {
updateCustodianTransactions,
custodianEventHandlerFactory,
showCustodianDeepLink,
} from "./ExtensionUtils";

export {
getWaitForConfirmDeepLinkDialog,
getTransactionStatusMap,
getCustodyAccountSupportedChains,
getMmiPortfolioEnabled,
getMmiPortfolioUrl,
getConfiguredCustodians,
getCustodianIconForAddress,
} from "./ExtensionSelectors";
export { updateCustodianTransactions, custodianEventHandlerFactory, showCustodianDeepLink } from "./ExtensionUtils";

export { mmiActionsFactory } from "./ExtensionActions";
40 changes: 25 additions & 15 deletions packages/sdk/src/custodianApi/bitgo/BitgoClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ export class BitgoClient {
const headers = this.getHeaders();

try {
const body = await fetch(`${this.bitgoApiurl}/wallets`, {
const response = await fetch(`${this.bitgoApiurl}/wallets`, {
headers,
});

if (!body.ok) {
throw new Error('Error fetching wallet accounts');
if (!response.ok) {
throw new Error(`Error fetching wallet accounts. Status: ${response.status} ${response.statusText}`);
}

const accounts: IBitgoGetEthereumAccountsResponse = await body.json();
const accounts: IBitgoGetEthereumAccountsResponse = await response.json();
return accounts.data;
} catch (e) {
throw new CustodianApiError(e);
Expand All @@ -52,15 +52,17 @@ export class BitgoClient {
const headers = this.getHeaders();

try {
const body = await fetch(`${this.bitgoApiurl}/mmi/wallets/address/${address}`, {
const response = await fetch(`${this.bitgoApiurl}/mmi/wallets/address/${address}`, {
headers,
});

if (!body.ok) {
throw new Error(`Error fetching account for address ${address}`);
if (!response.ok) {
throw new Error(
`Error fetching account for address ${address}. Status: ${response.status} ${response.statusText}`,
);
}

const accounts: IBitgoGetEthereumAccountsResponse = await body.json();
const accounts: IBitgoGetEthereumAccountsResponse = await response.json();
if (accounts.data.length) {
return accounts.data[0];
} else {
Expand Down Expand Up @@ -97,7 +99,7 @@ export class BitgoClient {
);

if (!response.ok) {
throw new Error('Error creating transaction');
throw new Error(`Error creating transaction. Status: ${response.status} ${response.statusText}`);
}

const resultWrapper: IBitgoCreateTransactionResponse = await response.json();
Expand All @@ -116,7 +118,9 @@ export class BitgoClient {
});

if (!response.ok) {
throw new Error(`Error getting transaction with id ${custodian_transactionId}`);
throw new Error(
`Error getting transaction with id ${custodian_transactionId}. Status: ${response.status} ${response.statusText}`,
);
}

const transaction = await response.json();
Expand All @@ -135,7 +139,7 @@ export class BitgoClient {
});

if (!response.ok) {
throw new Error('Error getting transactions');
throw new Error(`Error getting transactions. Status: ${response.status} ${response.statusText}`);
}

const allTransactions = await response.json();
Expand All @@ -158,7 +162,7 @@ export class BitgoClient {
});

if (!response.ok) {
throw new Error('Error getting Custommer Proof');
throw new Error(`Error getting Custommer Proof. Status: ${response.status} ${response.statusText}`);
}

const customerProof = await response.json();
Expand Down Expand Up @@ -191,7 +195,9 @@ export class BitgoClient {
});

if (!response.ok) {
throw new Error('Error doing signTypedData');
throw new Error(
`Error doing signTypedData from address: ${fromAddress}. Status: ${response.status} ${response.statusText}`,
);
}

const data = await response.json();
Expand Down Expand Up @@ -222,7 +228,9 @@ export class BitgoClient {
});

if (!response.ok) {
throw new Error('Error doing signPersonalMessage');
throw new Error(
`Error doing signPersonalMessage from address: ${fromAddress}. Status: ${response.status} ${response.statusText}`,
);
}

const data = await response.json();
Expand All @@ -248,7 +256,9 @@ export class BitgoClient {
);

if (!response.ok) {
throw new Error(`Error getting signed message with id ${custodian_signedMessageId}`);
throw new Error(
`Error getting signed message with id ${custodian_signedMessageId}. Status: ${response.status} ${response.statusText}`,
);
}

const data = await response.json();
Expand Down
Loading

0 comments on commit 6111794

Please sign in to comment.