From 46c536619b16c677523aa75a8f8a2ad7ee7e1b61 Mon Sep 17 00:00:00 2001 From: arrenv <33682027+arrenv@users.noreply.github.com> Date: Tue, 21 Feb 2023 13:16:45 +0100 Subject: [PATCH 1/3] Fix: Recovery page, debugging Safe page --- .../DetailsWidget/DetailsWidget.tsx | 11 ++++------- .../DetailsWidget/DetailsWidgetSafe/index.ts | 1 + .../ActionsPage/DetailsWidget/index.ts | 5 ----- src/utils/events/getAnnotationFromSubgraph.ts | 19 ++++++++++++++----- 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/modules/dashboard/components/ActionsPage/DetailsWidget/DetailsWidget.tsx b/src/modules/dashboard/components/ActionsPage/DetailsWidget/DetailsWidget.tsx index 4c454c3937..3e89295378 100644 --- a/src/modules/dashboard/components/ActionsPage/DetailsWidget/DetailsWidget.tsx +++ b/src/modules/dashboard/components/ActionsPage/DetailsWidget/DetailsWidget.tsx @@ -25,13 +25,10 @@ import { import { EventValues } from '../../ActionsPageFeed/ActionsPageFeed'; import { ACTION_TYPES_ICONS_MAP } from '../../ActionsPage/staticMaps'; -import { - DetailsWidgetTeam, - DetailsWidgetAddSafe, - DetailsWidgetRoles, - DetailsWidgetSafe, - DetailsWidgetSafeTransaction, -} from './index'; +import DetailsWidgetTeam from './DetailsWidgetTeam'; +import DetailsWidgetRoles from './DetailsWidgetRoles'; +import DetailsWidgetSafe, { DetailsWidgetAddSafe } from './DetailsWidgetSafe'; +import DetailsWidgetSafeTransaction from './DetailsWidgetSafeTransaction'; import styles from './DetailsWidget.css'; diff --git a/src/modules/dashboard/components/ActionsPage/DetailsWidget/DetailsWidgetSafe/index.ts b/src/modules/dashboard/components/ActionsPage/DetailsWidget/DetailsWidgetSafe/index.ts index 06cc0237cb..91550c6fee 100644 --- a/src/modules/dashboard/components/ActionsPage/DetailsWidget/DetailsWidgetSafe/index.ts +++ b/src/modules/dashboard/components/ActionsPage/DetailsWidget/DetailsWidgetSafe/index.ts @@ -1 +1,2 @@ export { default } from './DetailsWidgetSafe'; +export { default as DetailsWidgetAddSafe } from './DetailsWidgetAddSafe'; diff --git a/src/modules/dashboard/components/ActionsPage/DetailsWidget/index.ts b/src/modules/dashboard/components/ActionsPage/DetailsWidget/index.ts index 7ff407b94d..0e0f99a3ab 100644 --- a/src/modules/dashboard/components/ActionsPage/DetailsWidget/index.ts +++ b/src/modules/dashboard/components/ActionsPage/DetailsWidget/index.ts @@ -1,7 +1,2 @@ export { default } from './DetailsWidget'; export * from './DetailsWidget'; -export { default as DetailsWidgetTeam } from './DetailsWidgetTeam'; -export { default as DetailsWidgetRoles } from './DetailsWidgetRoles'; -export { default as DetailsWidgetSafe } from './DetailsWidgetSafe'; -export { default as DetailsWidgetAddSafe } from './DetailsWidgetSafe/DetailsWidgetAddSafe'; -export { default as DetailsWidgetSafeTransaction } from './DetailsWidgetSafeTransaction'; diff --git a/src/utils/events/getAnnotationFromSubgraph.ts b/src/utils/events/getAnnotationFromSubgraph.ts index 1f9708c9ed..d7f8b6e9fa 100644 --- a/src/utils/events/getAnnotationFromSubgraph.ts +++ b/src/utils/events/getAnnotationFromSubgraph.ts @@ -26,6 +26,7 @@ export const getAnnotationFromSubgraph = async ( fetchPolicy: 'network-only', }); + console.log('subgraphEvents', subgraphEvents); const [mostRecentAnnotation] = subgraphEvents?.annotationEvents .map(parseSubgraphEvent) @@ -35,11 +36,19 @@ export const getAnnotationFromSubgraph = async ( * be filtering these out, and show the most recent annotation, no matter * who sent it */ - .filter( - ({ values: { agent, address } }) => - agent.toLowerCase() === userAddress.toLowerCase() || - address.toLowerCase() === userAddress.toLowerCase(), - ) || []; + .filter(({ address, values: { agent }, values }) => { + console.log('getAnnotationFromSubgraph address', address); + console.log('getAnnotationFromSubgraph values', values); + console.log('getAnnotationFromSubgraph agent', agent); + console.log('userAddress', userAddress); + const userAddressLowered = userAddress.toLowerCase(); + return ( + agent.toLowerCase() === userAddressLowered || + address?.toLowerCase() === userAddressLowered || + values.address?.toLowerCase() === userAddressLowered + ); + }) || []; + console.log('mostRecentAnnotation', mostRecentAnnotation); return mostRecentAnnotation; }; From 23b06fd7cb0e3d84cd40f3b77470198f17232f8a Mon Sep 17 00:00:00 2001 From: arrenv <33682027+arrenv@users.noreply.github.com> Date: Fri, 24 Feb 2023 17:41:43 +0100 Subject: [PATCH 2/3] Fix: Safe Tx status null, add no provider catch --- .../hooks/useFetchSafeTransactionData.ts | 15 ++++-- .../dashboard/sagas/utils/safeHelpers.ts | 9 +++- src/utils/events/getAnnotationFromSubgraph.ts | 19 ++------ src/utils/safes/getTransactionStatuses.ts | 47 ++++++++++--------- 4 files changed, 47 insertions(+), 43 deletions(-) diff --git a/src/modules/dashboard/hooks/useFetchSafeTransactionData.ts b/src/modules/dashboard/hooks/useFetchSafeTransactionData.ts index be74c2bb5e..fc359c5735 100644 --- a/src/modules/dashboard/hooks/useFetchSafeTransactionData.ts +++ b/src/modules/dashboard/hooks/useFetchSafeTransactionData.ts @@ -85,11 +85,16 @@ export const useFetchSafeTransactionData = ( parsedAnnotation.safeData.chainId, transactionReceipt, ); - const safeTransactionStatus = safeTransactionStatuses.find( - (status) => status === TRANSACTION_STATUS.PENDING, - ) - ? TRANSACTION_STATUS.PENDING - : TRANSACTION_STATUS.SUCCESS; + let safeTransactionStatus; + if (safeTransactionStatuses.includes(TRANSACTION_STATUS.PENDING)) { + safeTransactionStatus = TRANSACTION_STATUS.PENDING; + } else if ( + safeTransactionStatuses.includes(TRANSACTION_STATUS.SUCCESS) + ) { + safeTransactionStatus = TRANSACTION_STATUS.SUCCESS; + } else { + safeTransactionStatus = null; + } setSafeTransactionData({ transactionTitle: parsedAnnotation.title, safeTransactionStatus, diff --git a/src/modules/dashboard/sagas/utils/safeHelpers.ts b/src/modules/dashboard/sagas/utils/safeHelpers.ts index 57debeb125..abbdd895c8 100644 --- a/src/modules/dashboard/sagas/utils/safeHelpers.ts +++ b/src/modules/dashboard/sagas/utils/safeHelpers.ts @@ -50,6 +50,9 @@ export const onLocalDevEnvironment = process.env.NODE_ENV === 'development'; export const getHomeProvider = () => { + if (!Web3.givenProvider) { + return null; + } return onLocalDevEnvironment ? new ethers.providers.JsonRpcProvider(LOCAL_HOME_CHAIN) : new ethers.providers.Web3Provider(Web3.givenProvider); // Metamask @@ -87,7 +90,7 @@ export const getForeignBridgeByChain = (safeChainId: string) => { export const getHomeBridgeByChain = (safeChainId: string) => { const homeProvider = getHomeProvider(); - const homeSigner = homeProvider.getSigner(); + const homeSigner = homeProvider?.getSigner(); const homeBridgeAddress: string | undefined = onLocalDevEnvironment ? LOCAL_HOME_BRIDGE_ADDRESS : GNOSIS_AMB_BRIDGES[safeChainId]?.homeAMB; @@ -98,7 +101,9 @@ export const getHomeBridgeByChain = (safeChainId: string) => { ); } // @ts-ignore abi type is wrong. - return new ethers.Contract(homeBridgeAddress, HomeAMB, homeSigner); + return homeSigner + ? new ethers.Contract(homeBridgeAddress, HomeAMB, homeSigner) + : null; }; const getErc721 = ( diff --git a/src/utils/events/getAnnotationFromSubgraph.ts b/src/utils/events/getAnnotationFromSubgraph.ts index d7f8b6e9fa..1f9708c9ed 100644 --- a/src/utils/events/getAnnotationFromSubgraph.ts +++ b/src/utils/events/getAnnotationFromSubgraph.ts @@ -26,7 +26,6 @@ export const getAnnotationFromSubgraph = async ( fetchPolicy: 'network-only', }); - console.log('subgraphEvents', subgraphEvents); const [mostRecentAnnotation] = subgraphEvents?.annotationEvents .map(parseSubgraphEvent) @@ -36,19 +35,11 @@ export const getAnnotationFromSubgraph = async ( * be filtering these out, and show the most recent annotation, no matter * who sent it */ - .filter(({ address, values: { agent }, values }) => { - console.log('getAnnotationFromSubgraph address', address); - console.log('getAnnotationFromSubgraph values', values); - console.log('getAnnotationFromSubgraph agent', agent); - console.log('userAddress', userAddress); - const userAddressLowered = userAddress.toLowerCase(); - return ( - agent.toLowerCase() === userAddressLowered || - address?.toLowerCase() === userAddressLowered || - values.address?.toLowerCase() === userAddressLowered - ); - }) || []; - console.log('mostRecentAnnotation', mostRecentAnnotation); + .filter( + ({ values: { agent, address } }) => + agent.toLowerCase() === userAddress.toLowerCase() || + address.toLowerCase() === userAddress.toLowerCase(), + ) || []; return mostRecentAnnotation; }; diff --git a/src/utils/safes/getTransactionStatuses.ts b/src/utils/safes/getTransactionStatuses.ts index 3237f49d63..06d9d82d65 100644 --- a/src/utils/safes/getTransactionStatuses.ts +++ b/src/utils/safes/getTransactionStatuses.ts @@ -110,28 +110,31 @@ export const getTransactionStatuses = async ( const homeAMBContract = getHomeBridgeByChain(safeChainId); const foreignAMBContract = getForeignBridgeByChain(safeChainId); - const messageIds = getMessageIds( - transactionReceipt, - homeAMBContract, - homeAMBContract.address, - ); + if (homeAMBContract) { + const messageIds = getMessageIds( + transactionReceipt, + homeAMBContract, + homeAMBContract?.address, + ); + const transactionStatuses = await Promise.all( + messageIds.map(async (messageId) => { + const wasTheMessageDelivered = await checkIfTheMessageWasDelivered( + foreignAMBContract, + networkApiURI, + messageId, + safeChainId, + ); + + // @NOTE: Safe transactions will always be executed automatically on the local env + if (wasTheMessageDelivered || onLocalDevEnvironment) { + return TRANSACTION_STATUS.SUCCESS; + } + return TRANSACTION_STATUS.PENDING; + }), + ); - const transactionStatuses = await Promise.all( - messageIds.map(async (messageId) => { - const wasTheMessageDelivered = await checkIfTheMessageWasDelivered( - foreignAMBContract, - networkApiURI, - messageId, - safeChainId, - ); - - // @NOTE: Safe transactions will always be executed automatically on the local env - if (wasTheMessageDelivered || onLocalDevEnvironment) { - return TRANSACTION_STATUS.SUCCESS; - } - return TRANSACTION_STATUS.PENDING; - }), - ); + return transactionStatuses; + } - return transactionStatuses; + return []; }; From 46bec85713098e8219225787025a52768d64405e Mon Sep 17 00:00:00 2001 From: arrenv <33682027+arrenv@users.noreply.github.com> Date: Fri, 24 Feb 2023 17:57:58 +0100 Subject: [PATCH 3/3] Fix: Null checks --- .../dashboard/sagas/actions/initiateSafeTransaction.ts | 4 ++-- .../dashboard/sagas/motions/initiateSafeTransactionMotion.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/modules/dashboard/sagas/actions/initiateSafeTransaction.ts b/src/modules/dashboard/sagas/actions/initiateSafeTransaction.ts index ad740afff3..12508a1483 100644 --- a/src/modules/dashboard/sagas/actions/initiateSafeTransaction.ts +++ b/src/modules/dashboard/sagas/actions/initiateSafeTransaction.ts @@ -109,7 +109,7 @@ function* initiateSafeTransactionAction({ } /* eslint-disable-next-line max-len */ - const txDataToBeSentToAMB = yield homeBridge.interface.functions.requireToPassMessage.encode( + const txDataToBeSentToAMB = yield homeBridge?.interface.functions.requireToPassMessage.encode( [zodiacBridgeModule.address, txDataToBeSentToZodiacModule, 1000000], ); @@ -142,7 +142,7 @@ function* initiateSafeTransactionAction({ methodName: 'makeArbitraryTransactions', identifier: colonyAddress, params: [ - fill(Array(transactionData.length), homeBridge.address), + fill(Array(transactionData.length), homeBridge?.address), transactionData, true, ], diff --git a/src/modules/dashboard/sagas/motions/initiateSafeTransactionMotion.ts b/src/modules/dashboard/sagas/motions/initiateSafeTransactionMotion.ts index 844f6d8d2b..9a9ec7f94b 100644 --- a/src/modules/dashboard/sagas/motions/initiateSafeTransactionMotion.ts +++ b/src/modules/dashboard/sagas/motions/initiateSafeTransactionMotion.ts @@ -152,7 +152,7 @@ function* initiateSafeTransactionMotion({ } /* eslint-disable-next-line max-len */ - const txDataToBeSentToAMB = yield homeBridge.interface.functions.requireToPassMessage.encode( + const txDataToBeSentToAMB = yield homeBridge?.interface.functions.requireToPassMessage.encode( [zodiacBridgeModule.address, txDataToBeSentToZodiacModule, 1000000], ); @@ -167,7 +167,7 @@ function* initiateSafeTransactionMotion({ * All the transactions will be send to the home bridge, therefore we just generate an array filled with the corresponding address. * */ - fill(Array(transactionData.length), homeBridge.address), + fill(Array(transactionData.length), homeBridge?.address), transactionData, true, ],