-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Safe SDK to send batched transactions
- Loading branch information
1 parent
f9f4058
commit 544b628
Showing
5 changed files
with
142 additions
and
17 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
packages/evmcrispr-terminal/src/components/ActionButtons/ExecuteButton.tsx
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,69 @@ | ||
import { ChevronDownIcon } from '@chakra-ui/icons'; | ||
import { | ||
Button, | ||
HStack, | ||
IconButton, | ||
Menu, | ||
MenuButton, | ||
MenuItem, | ||
MenuList, | ||
useBoolean, | ||
} from '@chakra-ui/react'; | ||
|
||
export function ExecuteButton({ | ||
isLoading, | ||
onExecute, | ||
allowBatch, | ||
}: { | ||
isLoading: boolean; | ||
onExecute: (inBatch: boolean) => void; | ||
allowBatch: boolean; | ||
}) { | ||
const [isBatch, setIsBatch] = useBoolean(allowBatch); | ||
|
||
return !allowBatch ? ( | ||
<Button | ||
variant="overlay" | ||
colorScheme={'green'} | ||
onClick={() => onExecute(isBatch)} | ||
isLoading={isLoading} | ||
loadingText={'Executing'} | ||
size={'md'} | ||
> | ||
Execute | ||
</Button> | ||
) : ( | ||
<HStack spacing={0}> | ||
<Button | ||
variant="overlay" | ||
colorScheme={'green'} | ||
onClick={() => onExecute(isBatch)} | ||
isLoading={isLoading} | ||
loadingText={'Executing'} | ||
size={'md'} | ||
borderRightRadius={0} | ||
> | ||
{isBatch ? 'Execute in batch' : 'Execute one by one'} | ||
</Button> | ||
{!isLoading && ( | ||
<Menu> | ||
<MenuButton | ||
as={IconButton} | ||
icon={<ChevronDownIcon />} | ||
variant="overlay" | ||
colorScheme={'green'} | ||
size={'md'} | ||
borderLeftRadius={0} | ||
borderLeft="1px solid" | ||
borderLeftColor="green.300" | ||
/> | ||
<MenuList> | ||
<MenuItem onClick={setIsBatch.toggle}> | ||
{isBatch ? 'Execute one by one' : 'Execute in batch'} | ||
</MenuItem> | ||
</MenuList> | ||
</Menu> | ||
)} | ||
</HStack> | ||
); | ||
} |
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
23 changes: 17 additions & 6 deletions
23
packages/evmcrispr-terminal/src/hooks/useSafeConnection.ts
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,19 +1,30 @@ | ||
import { useEffect } from 'react'; | ||
import { useEffect, useState } from 'react'; | ||
import { useAccount, useConnect } from 'wagmi'; | ||
import type { Connector } from 'wagmi'; | ||
import type { SafeInfo } from '@safe-global/safe-apps-sdk'; | ||
import SafeAppsSDK from '@safe-global/safe-apps-sdk'; | ||
|
||
export function useSafeConnection() { | ||
const [sdk, setSdk] = useState<SafeAppsSDK | undefined>(undefined); | ||
const [safe, setSafe] = useState<SafeInfo | undefined>(undefined); | ||
const { connector: activeConnector } = useAccount(); | ||
const { connectors, connectAsync } = useConnect(); | ||
const isSafe = activeConnector?.id === 'safe'; | ||
useEffect(() => { | ||
const safeConnector = connectors.find((c: Connector) => c.id === 'safe'); | ||
if (safeConnector && !isSafe && window.parent !== window) { | ||
connectAsync({ connector: safeConnector }).catch(() => { | ||
console.log('error connecting to safe'); | ||
}); | ||
connectAsync({ connector: safeConnector }) | ||
.then(() => { | ||
safeConnector.getProvider().then((provider) => { | ||
setSdk(new SafeAppsSDK((provider as any).sdk)); | ||
setSafe((provider as any).safe); | ||
}); | ||
}) | ||
.catch(() => { | ||
console.log('error connecting to safe'); | ||
}); | ||
} | ||
}, [connectors, connectAsync, activeConnector, isSafe]); | ||
}, [connectors, connectAsync, activeConnector?.id, isSafe]); | ||
|
||
return { isSafe }; | ||
return { isSafe, sdk, safe }; | ||
} |
27 changes: 27 additions & 0 deletions
27
packages/evmcrispr-terminal/src/theme/MenuCustomization.ts
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,27 @@ | ||
import { menuAnatomy } from '@chakra-ui/anatomy'; | ||
import { createMultiStyleConfigHelpers } from '@chakra-ui/react'; | ||
|
||
const { definePartsStyle, defineMultiStyleConfig } = | ||
createMultiStyleConfigHelpers(menuAnatomy.keys); | ||
|
||
const baseStyle = definePartsStyle({ | ||
list: { | ||
borderRadius: 'none', | ||
background: 'black', | ||
borderColor: 'green.300', | ||
padding: '0', | ||
}, | ||
item: { | ||
bg: 'black', | ||
_hover: { | ||
color: 'black', | ||
bg: 'green.300', | ||
}, | ||
}, | ||
}); | ||
|
||
const menuTheme = defineMultiStyleConfig({ | ||
baseStyle, | ||
}); | ||
|
||
export default menuTheme; |
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