Skip to content

Commit

Permalink
feat: improve Safe support (#323)
Browse files Browse the repository at this point in the history
  • Loading branch information
chybisov authored Nov 1, 2024
1 parent 2d14b78 commit 6f1e5d1
Show file tree
Hide file tree
Showing 22 changed files with 1,678 additions and 876 deletions.
6 changes: 3 additions & 3 deletions examples/deposit-flow/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
"preview": "vite preview"
},
"dependencies": {
"@lifi/sdk": "^3.4.0",
"@lifi/sdk": "^3.4.1",
"@lifi/widget": "workspace:^",
"@mui/material": "^5.16.7",
"@tanstack/react-query": "^5.59.16",
"events": "^3.3.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"viem": "^2.21.35",
"viem": "^2.21.37",
"wagmi": "^2.12.25"
},
"devDependencies": {
"@types/events": "^3.0.3",
"@types/node": "^22.8.4",
"@types/node": "^22.8.5",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@vitejs/plugin-react": "^4.3.3",
Expand Down
12 changes: 6 additions & 6 deletions examples/dynamic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
"preview": "vite preview"
},
"dependencies": {
"@dynamic-labs/bitcoin": "^3.4.4",
"@dynamic-labs/ethereum": "^3.4.4",
"@dynamic-labs/sdk-react-core": "^3.4.4",
"@dynamic-labs/solana": "^3.4.4",
"@dynamic-labs/wagmi-connector": "^3.4.4",
"@dynamic-labs/bitcoin": "^3.4.5",
"@dynamic-labs/ethereum": "^3.4.5",
"@dynamic-labs/sdk-react-core": "^3.4.5",
"@dynamic-labs/solana": "^3.4.5",
"@dynamic-labs/wagmi-connector": "^3.4.5",
"@lifi/wallet-management": "workspace:^",
"@lifi/widget": "workspace:^",
"@mui/material": "^5.16.7",
Expand All @@ -24,7 +24,7 @@
"mitt": "^3.0.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"viem": "^2.21.35",
"viem": "^2.21.37",
"wagmi": "^2.12.25"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion examples/nextjs-page-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"react-dom": "^18.3.1"
},
"devDependencies": {
"@types/node": "^22.8.4",
"@types/node": "^22.8.5",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"typescript": "^5.5.4"
Expand Down
4 changes: 2 additions & 2 deletions examples/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
"start": "next start"
},
"dependencies": {
"@lifi/sdk": "^3.4.0",
"@lifi/sdk": "^3.4.1",
"@lifi/widget": "^3.10.0",
"next": "^14.2.16",
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
"devDependencies": {
"@types/node": "^22.8.4",
"@types/node": "^22.8.5",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"typescript": "^5.5.4"
Expand Down
2 changes: 1 addition & 1 deletion examples/rainbowkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@tanstack/react-query": "^5.59.16",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"viem": "^2.21.35",
"viem": "^2.21.37",
"wagmi": "^2.12.25"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions examples/svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
"@sveltejs/vite-plugin-svelte": "^4.0.0",
"@tsconfig/svelte": "^5.0.4",
"@types/events": "^3.0.3",
"@types/node": "^22.8.4",
"@types/node": "^22.8.5",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"svelte": "^5.1.4",
"svelte": "^5.1.6",
"svelte-check": "^4.0.5",
"svelte-preprocess": "^6.0.2",
"tslib": "^2.8.0",
Expand Down
6 changes: 3 additions & 3 deletions examples/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"preview": "vite preview"
},
"dependencies": {
"@lifi/sdk": "^3.4.0",
"@lifi/sdk": "^3.4.1",
"@lifi/wallet-management": "^3.4.1",
"@lifi/widget": "workspace:^",
"@mui/material": "^5.16.5",
Expand All @@ -19,12 +19,12 @@
"events": "^3.3.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"viem": "^2.21.35",
"viem": "^2.21.37",
"wagmi": "^2.12.25"
},
"devDependencies": {
"@types/events": "^3.0.3",
"@types/node": "^22.8.4",
"@types/node": "^22.8.5",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@vitejs/plugin-react": "^4.3.3",
Expand Down
2 changes: 1 addition & 1 deletion examples/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
"typescript": "^5.5.4",
"vite": "^5.4.10",
"vite-plugin-node-polyfills": "^0.22.0",
"vue-tsc": "^2.1.8"
"vue-tsc": "^2.1.10"
}
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "3.10.0",
"version": "3.10.1-alpha.0",
"private": true,
"sideEffects": false,
"type": "module",
Expand Down Expand Up @@ -49,13 +49,13 @@
"@testing-library/react": "^16.0.1",
"@testing-library/user-event": "^14.5.2",
"@types/events": "^3.0.3",
"@types/node": "^22.8.4",
"@types/node": "^22.8.5",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"cpy-cli": "^5.0.0",
"fs-extra": "^11.2.0",
"husky": "^9.1.6",
"lerna": "8.1.8",
"lerna": "8.1.9",
"lint-staged": "^15.2.10",
"react": "^18.3.1",
"react-dom": "^18.3.1",
Expand Down
6 changes: 3 additions & 3 deletions packages/wallet-management/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lifi/wallet-management",
"version": "3.4.1",
"version": "3.4.2-alpha.0",
"description": "LI.FI Wallet Management solution.",
"type": "module",
"main": "./src/index.ts",
Expand Down Expand Up @@ -53,7 +53,7 @@
"@bigmi/react": "^0.0.4",
"@emotion/react": "^11.13.3",
"@emotion/styled": "^11.13.0",
"@lifi/sdk": "^3.4.0",
"@lifi/sdk": "^3.4.1",
"@mui/icons-material": "^5.16.7",
"@mui/lab": "^5.0.0-alpha.173",
"@mui/material": "^5.16.7",
Expand All @@ -67,7 +67,7 @@
"react": "^18.3.1",
"react-i18next": "^15.1.0",
"use-sync-external-store": "^1.2.2",
"viem": "^2.21.35",
"viem": "^2.21.37",
"wagmi": "^2.12.25",
"zustand": "^4.5.5"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/widget-embedded/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"author": "Eugene Chybisov <eugene@li.finance>",
"dependencies": {
"@lifi/sdk": "^3.4.0",
"@lifi/sdk": "^3.4.1",
"@lifi/wallet-management": "workspace:*",
"@lifi/widget": "workspace:*",
"@mui/icons-material": "^5.16.7",
Expand All @@ -28,7 +28,7 @@
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-router-dom": "^6.27.0",
"viem": "^2.21.35",
"viem": "^2.21.37",
"wagmi": "^2.12.25"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/widget-playground-next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
"@mui/material-nextjs": "^5.16.6",
"@mui/system": "^5.16.7",
"@tanstack/react-query": "^5.59.16",
"core-js": "^3.38.1",
"core-js": "^3.39.0",
"next": "14.2.15",
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
"devDependencies": {
"@types/node": "^22.8.4",
"@types/node": "^22.8.5",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"typescript": "^5.6.3"
Expand Down
6 changes: 3 additions & 3 deletions packages/widget-playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"dependencies": {
"@emotion/react": "^11.13.3",
"@emotion/styled": "^11.13.0",
"@lifi/sdk": "^3.4.0",
"@lifi/sdk": "^3.4.1",
"@lifi/wallet-management": "workspace:*",
"@lifi/widget": "workspace:*",
"@monaco-editor/react": "^4.6.0",
Expand All @@ -47,13 +47,13 @@
"microdiff": "^1.4.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"viem": "^2.21.35",
"viem": "^2.21.37",
"wagmi": "^2.12.25",
"zustand": "^4.5.1"
},
"devDependencies": {
"@types/lodash.isequal": "^4.5.8",
"@types/node": "^22.8.4",
"@types/node": "^22.8.5",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@vitejs/plugin-react-swc": "^3.7.1",
Expand Down
6 changes: 3 additions & 3 deletions packages/widget/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lifi/widget",
"version": "3.10.0",
"version": "3.10.1-alpha.0",
"description": "LI.FI Widget for cross-chain bridging and swapping. It will drive your multi-chain strategy and attract new users from everywhere.",
"type": "module",
"main": "./src/index.ts",
Expand Down Expand Up @@ -53,7 +53,7 @@
"@bigmi/react": "^0.0.4",
"@emotion/react": "^11.13.3",
"@emotion/styled": "^11.13.0",
"@lifi/sdk": "^3.4.0",
"@lifi/sdk": "^3.4.1",
"@lifi/wallet-management": "workspace:^",
"@mui/icons-material": "^5.16.7",
"@mui/lab": "^5.0.0-alpha.173",
Expand All @@ -72,7 +72,7 @@
"react-i18next": "^15.1.0",
"react-intersection-observer": "^9.13.1",
"react-router-dom": "^6.27.0",
"viem": "^2.21.35",
"viem": "^2.21.37",
"wagmi": "^2.12.25",
"zustand": "^4.5.5"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/widget/src/config/version.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const name = '@lifi/widget'
export const version = '3.10.0'
export const version = '3.10.1-alpha.0'
23 changes: 22 additions & 1 deletion packages/widget/src/hooks/useGasRefuel.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { useAccount } from '@lifi/wallet-management'
import { useMemo } from 'react'
import { useFieldValues } from '../stores/form/useFieldValues.js'
import { useAvailableChains } from './useAvailableChains.js'
import { useGasRecommendation } from './useGasRecommendation.js'
import { useIsContractAddress } from './useIsContractAddress.js'
import { useTokenBalance } from './useTokenBalance.js'

export const useGasRefuel = () => {
Expand All @@ -17,6 +19,19 @@ export const useGasRefuel = () => {
const toChain = getChainById(toChainId)
const fromChain = getChainById(fromChainId)

const { account } = useAccount({ chainType: fromChain?.chainType })

const isFromContractAddress = useIsContractAddress(
account.address,
fromChainId,
account.chainType
)
const isToContractAddress = useIsContractAddress(
toAddress,
toChainId,
toChain?.chainType
)

const { token: nativeToken } = useTokenBalance(
toAddress,
toChainId ? toChain?.nativeToken : undefined,
Expand All @@ -33,6 +48,10 @@ export const useGasRefuel = () => {
const isChainTypeSatisfied =
fromChain?.chainType !== toChain?.chainType ? Boolean(toAddress) : true

const isToAddressSatisfied = isFromContractAddress
? toAddress && toAddress !== account.address && !isToContractAddress
: true

const enabled = useMemo(() => {
if (
// We don't allow same chain refuel.
Expand All @@ -41,7 +60,8 @@ export const useGasRefuel = () => {
!gasRecommendation?.available ||
!gasRecommendation?.recommended ||
!nativeToken ||
!isChainTypeSatisfied
!isChainTypeSatisfied ||
!isToAddressSatisfied
) {
return false
}
Expand All @@ -56,6 +76,7 @@ export const useGasRefuel = () => {
fromChainId,
gasRecommendation,
isChainTypeSatisfied,
isToAddressSatisfied,
nativeToken,
toChainId,
])
Expand Down
5 changes: 4 additions & 1 deletion packages/widget/src/hooks/useToAddressRequirements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ export const useToAddressRequirements = () => {
const isDifferentChainType =
fromChain && toChain && fromChain.chainType !== toChain.chainType

const isCrossChainContractAddress =
isFromContractAddress && fromChainId !== toChainId

const requiredToAddress =
requiredUI?.includes(RequiredUI.ToAddress) ||
isDifferentChainType ||
isFromContractAddress
isCrossChainContractAddress

return {
requiredToAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ export const StatusBottomSheetContent: React.FC<
subvariantOptions,
contractSecondaryComponent,
contractCompactComponent,
feeConfig,
} = useWidgetConfig()
const { getChainById } = useAvailableChains()

Expand Down Expand Up @@ -252,9 +251,6 @@ export const StatusBottomSheetContent: React.FC<
hasEnumFlag(status, RouteExecutionStatus.Done) &&
(contractCompactComponent || contractSecondaryComponent)

const VcComponent =
status === RouteExecutionStatus.Done ? feeConfig?._vcComponent : undefined

return (
<Box p={3} ref={ref}>
{!showContractComponent ? (
Expand Down Expand Up @@ -300,7 +296,6 @@ export const StatusBottomSheetContent: React.FC<
{secondaryMessage ? (
<Typography py={1}>{secondaryMessage}</Typography>
) : null}
{VcComponent ? <VcComponent route={route} /> : null}
<Box sx={{ display: 'flex', marginTop: 2, gap: 1.5 }}>
{hasEnumFlag(status, RouteExecutionStatus.Done) ? (
<Button variant="text" onClick={handleSeeDetails} fullWidth>
Expand Down
Loading

0 comments on commit 6f1e5d1

Please sign in to comment.