-
Notifications
You must be signed in to change notification settings - Fork 423
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat/sign-ui' into tmp/20241018
- Loading branch information
Showing
22 changed files
with
162 additions
and
301 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
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,49 @@ | ||
import { useWalletConnectIcon } from '../component/WalletConnect/useWalletConnectIcon'; | ||
import { useThemeMode } from './usePreference'; | ||
import React from 'react'; | ||
import { pickKeyringThemeIcon } from '@/utils/account'; | ||
import { | ||
KEYRING_ICONS, | ||
KEYRINGS_LOGOS, | ||
WALLET_BRAND_CONTENT, | ||
} from '@/constant'; | ||
|
||
export const useBrandIcon = ({ | ||
address, | ||
brandName, | ||
type, | ||
forceLight, | ||
}: { | ||
address: string; | ||
brandName: string; | ||
type: string; | ||
forceLight?: boolean; | ||
}) => { | ||
const brandIcon = useWalletConnectIcon({ | ||
address, | ||
brandName, | ||
type, | ||
}); | ||
|
||
const { isDarkTheme } = useThemeMode(); | ||
|
||
const addressTypeIcon = React.useMemo( | ||
() => | ||
forceLight | ||
? brandIcon || | ||
pickKeyringThemeIcon(type as any, { | ||
needLightVersion: true, | ||
}) || | ||
WALLET_BRAND_CONTENT?.[brandName]?.image || | ||
KEYRINGS_LOGOS[type] | ||
: brandIcon || | ||
pickKeyringThemeIcon(brandName as any, { | ||
needLightVersion: isDarkTheme, | ||
}) || | ||
WALLET_BRAND_CONTENT?.[brandName]?.image || | ||
KEYRING_ICONS[type], | ||
[type, brandName, brandIcon, isDarkTheme] | ||
); | ||
|
||
return addressTypeIcon; | ||
}; |
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,57 @@ | ||
import { KEYRING_CLASS } from '@/constant'; | ||
import React from 'react'; | ||
import { useLedgerStatus } from '../component/ConnectStatus/useLedgerStatus'; | ||
import { useCommonPopupView } from './WalletContext'; | ||
import { useSessionStatus } from '../component/WalletConnect/useSessionStatus'; | ||
import { useCurrentAccount } from '../hooks/backgroundState/useAccount'; | ||
import { useImKeyStatus } from '../component/ConnectStatus/useImKeyStatus'; | ||
|
||
/** | ||
* some devices require a connection to the device to sign transactions | ||
* ledger, walletConnect, gridplus, etc | ||
*/ | ||
export const useDeviceConnect = () => { | ||
const ledgerStatus = useLedgerStatus(); | ||
const account = useCurrentAccount(); | ||
const walletConnectStatus = useSessionStatus(account!); | ||
const imKeyStatus = useImKeyStatus(); | ||
const { activePopup, setAccount } = useCommonPopupView(); | ||
|
||
/** | ||
* @returns {boolean} true if connected, false if not connected and popup is shown | ||
*/ | ||
const connect = React.useCallback( | ||
(type: string) => { | ||
if (type === KEYRING_CLASS.HARDWARE.LEDGER) { | ||
if (ledgerStatus.status === 'DISCONNECTED') { | ||
activePopup('Ledger'); | ||
return false; | ||
} | ||
} else if (type === KEYRING_CLASS.WALLETCONNECT) { | ||
if ( | ||
!walletConnectStatus.status || | ||
walletConnectStatus.status === 'DISCONNECTED' | ||
) { | ||
if (account) { | ||
setAccount({ | ||
...account, | ||
type, | ||
}); | ||
} | ||
activePopup('WalletConnect'); | ||
return false; | ||
} | ||
} else if (type === KEYRING_CLASS.HARDWARE.IMKEY) { | ||
if (imKeyStatus.status === 'DISCONNECTED') { | ||
activePopup('ImKeyPermission'); | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
}, | ||
[ledgerStatus, walletConnectStatus, imKeyStatus, account] | ||
); | ||
|
||
return connect; | ||
}; |
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
Oops, something went wrong.