Skip to content

Commit

Permalink
fix: gnosis safe tx
Browse files Browse the repository at this point in the history
  • Loading branch information
Argeare5 committed Nov 16, 2023
1 parent 50e2eab commit 915ceac
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 26 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@bgd-labs/frontend-web3-utils",
"description": "Frontend utilities common to multiple Web3 projects",
"version": "0.4.70",
"version": "0.4.71",
"author": "BGD labs",
"license": "MIT",
"private": false,
Expand Down
39 changes: 36 additions & 3 deletions src/web3/adapters/EthereumAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { produce } from 'immer';
import { Hex, isHex } from 'viem';

import { SafeTransactionServiceUrls } from '../../utils/constants';
import { setLocalStorageTxPool } from '../../utils/localStorage';
import {
BaseTx,
Expand Down Expand Up @@ -51,10 +52,42 @@ export class EthereumAdapter<T extends BaseTx> implements AdapterInterface<T> {
payload: payload,
from,
};
const txPool = this.get().addTXToPool(txParams, activeWallet.walletType);

this.waitForTxReceipt(txParams.hash);
return txPool[txParams.hash];
if (activeWallet.walletType === 'WalletConnect') {
// check if tx real on safe (need for safe + wallet connect)
const response = await fetch(
`${
SafeTransactionServiceUrls[txParams.chainId]
}/multisig-transactions/${tx}/`,
);

if (response.ok) {
const args = {
tx,
payload,
activeWallet,
chainId,
type,
};

this.get().updateEthAdapter(true);
return this.get().ethereumAdapter.executeTx(args);
} else {
const txPool = this.get().addTXToPool(
txParams,
activeWallet.walletType,
);
this.waitForTxReceipt(txParams.hash);
return txPool[txParams.hash];
}
} else {
const txPool = this.get().addTXToPool(
txParams,
activeWallet.walletType,
);
this.waitForTxReceipt(txParams.hash);
return txPool[txParams.hash];
}
} else {
return undefined;
}
Expand Down
50 changes: 33 additions & 17 deletions src/web3/adapters/GnosisAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,47 +75,63 @@ export class GnosisAdapter<T extends BaseTx> implements AdapterInterface<T> {
type,
payload: payload,
from,
isSafeTx: true,
};

if (isSafeTx(tx)) {
console.log('safe tx', tx);
const txParams = {
...initialParams,
hash: tx.safeTxHash,
};
console.log('safe txParams', txParams);
// @ts-ignore
const txPool = this.get().addTXToPool(txParams, activeWallet.walletType);
this.startTxTracking(txParams.hash);
return txPool[txParams.hash];
} else if (isHex(tx)) {
console.log('hex tx', tx);

const txParams = {
...initialParams,
hash: tx,
};

// check if tx real on safe (need for safe + wallet connect)
const response = await fetch(
`${
SafeTransactionServiceUrls[initialParams.chainId]
}/multisig-transactions/${tx}/`,
);
console.log('hex txParams', txParams);

if (activeWallet.walletType === 'WalletConnect') {
// check if tx real on safe (need for safe + wallet connect)
const response = await fetch(
`${
SafeTransactionServiceUrls[initialParams.chainId]
}/multisig-transactions/${tx}/`,
);

if (response.ok) {
if (response.ok) {
const txPool = this.get().addTXToPool(
txParams,
activeWallet.walletType,
);
this.startTxTracking(txParams.hash);
return txPool[txParams.hash];
} else {
const args = {
tx,
payload,
activeWallet,
chainId,
type,
};
this.get().updateEthAdapter(false);
return this.get().ethereumAdapter.executeTx(args);
}
} else {
const txPool = this.get().addTXToPool(
txParams,
activeWallet.walletType,
);
this.startTxTracking(txParams.hash);
return txPool[txParams.hash];
} else {
const args = {
tx,
payload,
activeWallet,
chainId,
type,
};
this.get().updateEthAdapter(false);
return this.get().ethereumAdapter.executeTx(args);
}
} else {
return undefined;
Expand Down
3 changes: 1 addition & 2 deletions src/web3/store/transactionsSelectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ export const selectTxExplorerLink = <T extends BaseTx>(
state: ITransactionsState<T>,
getChainParameters: (chainId: number) => Chain,
txHash: Hex,
isWalletContract?: boolean,
replacedTxHash?: Hex,
) => {
const tx = selectTXByHash(state, txHash);
Expand All @@ -94,7 +93,7 @@ export const selectTxExplorerLink = <T extends BaseTx>(
}

const returnValue = (hash: string) => {
if (tx.walletType !== 'GnosisSafe' && !isWalletContract) {
if (tx.walletType !== 'GnosisSafe' && tx.isSafeTx) {
return `${getChainParameters(tx.chainId).blockExplorers?.default
.url}/tx/${hash}`;
} else {
Expand Down
1 change: 1 addition & 0 deletions src/web3/store/transactionsSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export type BasicTx = {
payload?: object;
timestamp?: number;
errorMessage?: string;
isSafeTx?: boolean;
};

export type EthBaseTx = BasicTx & {
Expand Down
3 changes: 0 additions & 3 deletions src/web3/store/walletSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,6 @@ export function createWalletSlice({
get().setClient(wallet.chain.id, client);
walletConnected(activeWallet);
set({ isActiveWalletSetting: false });
if (isContractAddress) {
get().updateEthAdapter(true);
}
}
}
}
Expand Down

0 comments on commit 915ceac

Please sign in to comment.