Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post eco fixes #1210

Merged
merged 9 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/cold-donuts-film.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"alephium-desktop-wallet": patch
---

Fix display of dApp messages
5 changes: 5 additions & 0 deletions .changeset/hip-eyes-lay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@alephium/mobile-wallet": patch
---

Add dApp links to Alph.land
5 changes: 5 additions & 0 deletions .changeset/ten-papayas-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@alephium/mobile-wallet": patch
---

Copy bytecode in dApp request modal
4 changes: 2 additions & 2 deletions apps/mobile-wallet/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ PODS:
- Yoga
- ExpoAsset (10.0.10):
- ExpoModulesCore
- ExpoBlur (13.0.2):
- ExpoBlur (13.0.3):
- ExpoModulesCore
- ExpoCamera (15.0.16):
- ExpoModulesCore
Expand Down Expand Up @@ -2082,7 +2082,7 @@ SPEC CHECKSUMS:
expo-dev-menu: 8b0ea59392e2dd975390ea6f0472ce350d94866a
expo-dev-menu-interface: 5c6b79875bf0ab1251ea9962f60968fe39ed2637
ExpoAsset: 286fee7ba711ce66bf20b315e68106b13b8629fc
ExpoBlur: d6023b4ccd20035624b60ae0bda541e65b9ece5c
ExpoBlur: 99901a4531f5d3ac4a19b362907b8f75da4ed9c8
ExpoCamera: cf49d2d121a9f883be0f98dde15a2185a1dd42be
ExpoClipboard: 243e22ff4161bbffcd3d2db469ae860ddc1156be
ExpoDevice: 84b3ed79df1234c17edfbf335f6ecf3c636f74de
Expand Down
5 changes: 4 additions & 1 deletion apps/mobile-wallet/locales/en-US/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@
"Saving": "Saving",
"Saved!": "Saved!",
"Copy address": "Copy address",
"Copy": "Copy",
"Bytecode copied": "Bytecode copied",
"Paste": "Paste",
"Edit": "Edit",
"Share": "Share",
Expand Down Expand Up @@ -453,5 +455,6 @@
"Did you know?": "Did you know?",
"Splitting your funds into multiple addresses can help you stay organized and increase privacy.": "Splitting your funds into multiple addresses can help you stay organized and increase privacy.",
"No dApps match your search: \"{{ searchText }}\"": "No dApps match your search: \"{{ searchText }}\"",
"Visit dApp": "Visit dApp"
"Visit dApp": "Visit dApp",
"More details on Alph.land": "More details on Alph.land"
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ export default QuickActionButton

const QuickActionButtonStyled = styled(Button)`
border-radius: ${BORDER_RADIUS_BIG}px;
background-color: ${({ theme }) => theme.button.secondary};
`
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ interface WalletConnectContextValue {

resetWalletConnectClientInitializationAttempts: () => void
resetWalletConnectStorage: () => void
isInEcosystemInAppBrowser: boolean
setIsInEcosystemInAppBrowser: (value: boolean) => void
}

const initialValues: WalletConnectContextValue = {
Expand All @@ -104,7 +106,9 @@ const initialValues: WalletConnectContextValue = {
respondToWalletConnect: () => Promise.resolve(),

resetWalletConnectClientInitializationAttempts: () => null,
resetWalletConnectStorage: () => null
resetWalletConnectStorage: () => null,
isInEcosystemInAppBrowser: false,
setIsInEcosystemInAppBrowser: () => null
}

const WalletConnectContext = createContext(initialValues)
Expand All @@ -129,6 +133,7 @@ export const WalletConnectContextProvider = ({ children }: { children: ReactNode
const [walletConnectClient, setWalletConnectClient] = useState<WalletConnectContextValue['walletConnectClient']>()
const [activeSessions, setActiveSessions] = useState<SessionTypes.Struct[]>([])
const [walletConnectClientInitializationAttempts, setWalletConnectClientInitializationAttempts] = useState(0)
const [isInEcosystemInAppBrowser, setIsInEcosystemInAppBrowser] = useState(false)

const isWalletConnectClientReady =
isWalletConnectEnabled && walletConnectClient && walletConnectClientStatus === 'initialized'
Expand Down Expand Up @@ -882,7 +887,9 @@ export const WalletConnectContextProvider = ({ children }: { children: ReactNode
resetWalletConnectClientInitializationAttempts,
resetWalletConnectStorage,
respondToWalletConnectWithError,
respondToWalletConnect
respondToWalletConnect,
isInEcosystemInAppBrowser,
setIsInEcosystemInAppBrowser
}}
>
{children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import Button from '~/components/buttons/Button'
import ButtonsRow from '~/components/buttons/ButtonsRow'
import InfoBox from '~/components/InfoBox'
import { ScreenSection } from '~/components/layout/Screen'
import useWalletConnectToasts from '~/contexts/walletConnect/useWalletConnectToasts'
import { useWalletConnectContext } from '~/contexts/walletConnect/WalletConnectContext'
import { activateAppLoading, deactivateAppLoading } from '~/features/loader/loaderActions'
import BottomModal from '~/features/modals/BottomModal'
Expand Down Expand Up @@ -57,6 +58,7 @@ const WalletConnectSessionProposalModal = withModal<WalletConnectSessionProposal
const persistAddressSettings = usePersistAddressSettings()
const { t } = useTranslation()
const { walletConnectClient, activeSessions, refreshActiveSessions } = useWalletConnectContext()
const { showApprovedToast, showRejectedToast } = useWalletConnectToasts()

const [signerAddress, setSignerAddress] = useState<Address>()
const [showAlternativeSignerAddresses, setShowAlternativeSignerAddresses] = useState(false)
Expand Down Expand Up @@ -179,7 +181,7 @@ const WalletConnectSessionProposalModal = withModal<WalletConnectSessionProposal
} finally {
refreshActiveSessions()
dispatch(deactivateAppLoading())
showToast({ text1: t('dApp request approved'), text2: t('You can go back to your browser.') })
showApprovedToast()
dispatch(closeModal({ id: modalId }))
}
}
Expand All @@ -197,7 +199,7 @@ const WalletConnectSessionProposalModal = withModal<WalletConnectSessionProposal
} finally {
refreshActiveSessions()
dispatch(deactivateAppLoading())
showToast({ text1: t('dApp request rejected'), text2: t('You can go back to your browser.'), type: 'info' })
showRejectedToast()
dispatch(closeModal({ id: modalId }))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
transactionSign
} from '@alephium/web3'
import { getSdkError } from '@walletconnect/utils'
import * as Clipboard from 'expo-clipboard'
import { useState } from 'react'
import { useTranslation } from 'react-i18next'
import { Image } from 'react-native'
import styled from 'styled-components/native'
Expand All @@ -31,10 +33,10 @@ import AppText from '~/components/AppText'
import AssetAmountWithLogo from '~/components/AssetAmountWithLogo'
import Button from '~/components/buttons/Button'
import ButtonsRow from '~/components/buttons/ButtonsRow'
import ExpandableRow from '~/components/ExpandableRow'
import { ModalScreenTitle, ScreenSection } from '~/components/layout/Screen'
import Surface from '~/components/layout/Surface'
import Row from '~/components/Row'
import useWalletConnectToasts from '~/contexts/walletConnect/useWalletConnectToasts'
import { useWalletConnectContext } from '~/contexts/walletConnect/WalletConnectContext'
import useFundPasswordGuard from '~/features/fund-password/useFundPasswordGuard'
import { activateAppLoading, deactivateAppLoading } from '~/features/loader/loaderActions'
Expand Down Expand Up @@ -64,28 +66,21 @@ const WalletConnectSessionRequestModal = withModal(
requestEvent
}: WalletConnectSessionRequestModalProps<T> & ModalBaseProp) => {
const dispatch = useAppDispatch()
const { walletConnectClient, respondToWalletConnect, respondToWalletConnectWithError, activeSessions } =
useWalletConnectContext()
const { respondToWalletConnect, respondToWalletConnectWithError, activeSessions } = useWalletConnectContext()
const signAddress = useAppSelector((s) => selectAddressByHash(s, requestData.wcData.fromAddress))
const { t } = useTranslation()
const { triggerBiometricsAuthGuard } = useBiometricsAuthGuard()
const { triggerFundPasswordAuthGuard } = useFundPasswordGuard()
const { showApprovedToast, showRejectedToast } = useWalletConnectToasts()

const metadata = activeSessions.find((s) => s.topic === requestEvent?.topic)?.peer.metadata
const [isApproving, setIsApproving] = useState(false)

const metadata = activeSessions.find((s) => s.topic === requestEvent.topic)?.peer.metadata
const isSignRequest = requestData.type === 'sign-message' || requestData.type === 'sign-unsigned-tx'
const fees = !isSignRequest
? BigInt(requestData.unsignedTxData.gasAmount) * BigInt(requestData.unsignedTxData.gasPrice)
: undefined

const handleManualClose = () => {
console.log('👉 CLOSING MODAL.')

if (requestEvent && walletConnectClient && walletConnectClient?.getPendingSessionRequests().length > 0) {
console.log('👉 USER CLOSED THE MODAL WITHOUT REJECTING/APPROVING SO WE NEED TO REJECT.')
onReject()
}
}

const handleApprovePress = () => onApprove(sendTransaction)

const sendTransaction = async () => {
Expand Down Expand Up @@ -261,7 +256,7 @@ const WalletConnectSessionRequestModal = withModal(
console.log('✅ INFORMING: DONE!')

console.log('👉 RESETTING SESSION REQUEST EVENT.')
showToast({ text1: t('dApp request approved'), text2: t('You can go back to your browser.') })
showApprovedToast()
}

const onReject = async () => {
Expand All @@ -272,7 +267,7 @@ const WalletConnectSessionRequestModal = withModal(
} catch (e) {
console.error('❌ INFORMING: FAILED.')
} finally {
showToast({ text1: t('dApp request rejected'), text2: t('You can go back to your browser.'), type: 'info' })
showRejectedToast()
dispatch(closeModal({ id }))
}
}
Expand All @@ -293,16 +288,16 @@ const WalletConnectSessionRequestModal = withModal(
sendTransaction: () => Promise<
SignExecuteScriptTxResult | SignDeployContractTxResult | SignTransferTxResult | undefined
>
) => {
if (!requestEvent) return

) =>
triggerBiometricsAuthGuard({
settingsToCheck: 'transactions',
successCallback: () =>
triggerFundPasswordAuthGuard({
successCallback: async () => {
dispatch(activateAppLoading(t('Approving')))

setIsApproving(true)

try {
const signResult = await sendTransaction()

Expand All @@ -327,16 +322,15 @@ const WalletConnectSessionRequestModal = withModal(
} finally {
console.log('👉 RESETTING SESSION REQUEST EVENT.')
dispatch(deactivateAppLoading())
showToast({ text1: t('dApp request approved'), text2: t('You can go back to your browser.') })
showApprovedToast()
dispatch(closeModal({ id }))
}
}
})
})
}

return (
<BottomModal modalId={id} onClose={handleManualClose}>
<BottomModal modalId={id} onClose={!isApproving ? onReject : undefined}>
<ModalContent verticalGap>
{metadata && (
<ScreenSection>
Expand Down Expand Up @@ -380,7 +374,7 @@ const WalletConnectSessionRequestModal = withModal(

{requestData.type === 'deploy-contract' || requestData.type === 'call-contract' ? (
metadata?.url && (
<Row title={t('To')} titleColor="secondary">
<Row title={t('To')} titleColor="secondary" noMaxWidth>
<AppText semiBold>{metadata.url}</AppText>
</Row>
)
Expand Down Expand Up @@ -410,17 +404,7 @@ const WalletConnectSessionRequestModal = withModal(
)}

{(requestData.type === 'deploy-contract' || requestData.type === 'call-contract') && (
<ExpandableRow
titleComponent={
<AppTextStyled medium color="secondary">
{t('Bytecode')}
</AppTextStyled>
}
>
<Row isVertical>
<AppText>{requestData.wcData.bytecode}</AppText>
</Row>
</ExpandableRow>
<CopyBytecodeRow bytecode={requestData.wcData.bytecode} />
)}
{requestData.type === 'sign-unsigned-tx' && (
<>
Expand Down Expand Up @@ -467,6 +451,21 @@ const WalletConnectSessionRequestModal = withModal(

export default WalletConnectSessionRequestModal

const CopyBytecodeRow = ({ bytecode }: { bytecode: string }) => {
const { t } = useTranslation()

const handleCopy = () => {
Clipboard.setStringAsync(bytecode)
showToast({ text1: t('Bytecode copied') })
}

return (
<Row title={t('Bytecode')} titleColor="secondary" isLast>
<Button iconProps={{ name: 'copy' }} onPress={handleCopy} />
</Row>
)
}

const AssetAmounts = styled.View`
gap: 5px;
align-items: flex-end;
Expand All @@ -484,7 +483,3 @@ const DAppIcon = styled(Image)`
width: 50px;
height: 50px;
`

const AppTextStyled = styled(AppText)`
padding-left: 14px;
`
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { useTranslation } from 'react-i18next'

import { useWalletConnectContext } from '~/contexts/walletConnect/WalletConnectContext'
import { showToast } from '~/utils/layout'

const useWalletConnectToasts = () => {
const { isInEcosystemInAppBrowser } = useWalletConnectContext()
const { t } = useTranslation()

const text2 = !isInEcosystemInAppBrowser ? t('You can go back to your browser.') : undefined

return {
showApprovedToast: () => showToast({ text1: t('dApp request approved'), text2 }),
showRejectedToast: () => showToast({ text1: t('dApp request rejected'), text2, type: 'info' })
}
}

export default useWalletConnectToasts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const TokenRoundedCard = ({ tokenId, addressHash }: TokenAnimatedBackgroundProps
: darkTheme.font.primary)

useEffect(() => {
if (!tokenLogoUri) return
if (!tokenLogoUri || tokenId === ALPH.id) return

getColors(tokenLogoUri, {
fallback: '#228B22',
Expand All @@ -97,7 +97,7 @@ const TokenRoundedCard = ({ tokenId, addressHash }: TokenAnimatedBackgroundProps
.toHex()
)
})
}, [theme.name, tokenLogoUri])
}, [theme.name, tokenId, tokenLogoUri])

return (
<RoundedCard>
Expand Down
Loading