-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: select available signer in SafeTxProvider, disable signers that …
…already signed
- Loading branch information
Showing
6 changed files
with
74 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/components/tx/SignOrExecuteForm/SignerForm/styles.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
.signerForm :global .MuiOutlinedInput-notchedOutline { | ||
border: 1px solid var(--color-border-light) !important; | ||
} | ||
|
||
.disabledPill { | ||
background-color: var(--color-border-light); | ||
border-radius: 4px; | ||
color: var(--color-text-primary); | ||
padding: 4px 8px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { useMemo, useEffect } from 'react' | ||
import { useWalletContext } from './useWallet' | ||
import type { SafeInfo } from '@safe-global/safe-gateway-typescript-sdk' | ||
import type { SafeTransaction } from '@safe-global/safe-core-sdk-types' | ||
import { useNestedSafeOwners } from '../useNestedSafeOwners' | ||
import { sameAddress } from '@/utils/addresses' | ||
|
||
const useAvailableSigners = (tx: SafeTransaction | undefined, safe: SafeInfo) => { | ||
const { connectedWallet: wallet } = useWalletContext() ?? {} | ||
|
||
const nestedSafeOwners = useNestedSafeOwners() | ||
|
||
const isDirectOwner = useMemo( | ||
() => typeof wallet?.address === 'string' && safe.owners.map((owner) => owner.value).includes(wallet.address), | ||
[wallet?.address, safe], | ||
) | ||
|
||
return useMemo(() => { | ||
const result = nestedSafeOwners?.filter((owner) => !tx?.signatures.has(owner.toLowerCase())) ?? [] | ||
if (wallet?.address && isDirectOwner && !tx?.signatures.has(wallet.address.toLowerCase())) { | ||
result?.push(wallet.address) | ||
} | ||
return result | ||
}, [isDirectOwner, nestedSafeOwners, tx?.signatures, wallet?.address]) | ||
} | ||
|
||
export const useSelectAvailableSigner = (tx: SafeTransaction | undefined, safe: SafeInfo) => { | ||
const { signer, setSignerAddress } = useWalletContext() ?? {} | ||
const availableSigners = useAvailableSigners(tx, safe) | ||
|
||
// Sets the first available signer if non is set | ||
useEffect(() => { | ||
// Make sure the current signer can sign the tx | ||
if (availableSigners.some((available) => sameAddress(signer?.address, available))) { | ||
return | ||
} | ||
|
||
setSignerAddress?.(availableSigners[0]) | ||
}, [availableSigners, safe, setSignerAddress, signer?.address, tx]) | ||
} | ||
|
||
export default useAvailableSigners |