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

Adds a ENS address selector to the Profile page #367

Merged
merged 25 commits into from
Apr 18, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b3769c1
add base ens name selector in Profile
ramirotw Dec 7, 2021
f7e62d0
fix styles
alongoni Dec 13, 2021
54b2683
fix codegen schema error
ramirotw Dec 16, 2021
e902cb6
Merge remote-tracking branch 'origin/develop' into ramirotw/issue-168…
ramirotw Dec 16, 2021
54dc4a7
handle error for xdai
ramirotw Dec 16, 2021
e1b5e33
shorten address in dropdown
ramirotw Dec 16, 2021
3361d68
Merge remote-tracking branch 'origin/develop' into ramirotw/issue-168…
ramirotw Feb 18, 2022
117545f
only show the address selector on mainnet
ramirotw Feb 18, 2022
828b2e1
Fix code style issues with Prettier
lint-action Feb 18, 2022
c8a3118
Merge remote-tracking branch 'origin/develop' into ramirotw/issue-168…
ramirotw Apr 1, 2022
0bc1579
handle account change
ramirotw Apr 1, 2022
97dce07
Merge remote-tracking branch 'origin/ramirotw/issue-1682-ens-affiliat…
ramirotw Apr 1, 2022
3837a52
parse ens name from qs
ramirotw Apr 1, 2022
49a1455
Merge remote-tracking branch 'origin/develop' into ramirotw/issue-168…
ramirotw Apr 8, 2022
db2b7bb
bump graphql-request
ramirotw Apr 8, 2022
8057369
show full address when there are no ens names
ramirotw Apr 11, 2022
13607b4
disable dropdown if there are no ens names
ramirotw Apr 12, 2022
5c0a805
add rinkeby subgraph
ramirotw Apr 12, 2022
7d529a9
remove dropdown when there's no ens names
ramirotw Apr 12, 2022
a804a4c
shorten always referral address
ramirotw Apr 13, 2022
571f64d
prevent returning an invalid state due to a loading variable
ramirotw Apr 13, 2022
1a95e1d
Update src/custom/hooks/useParseReferralQueryParam.ts
ramirotw Apr 14, 2022
93aa746
fix wrong utils path
ramirotw Apr 18, 2022
83092f2
merge useEffects hooks
ramirotw Apr 18, 2022
bcca83d
Merge remote-tracking branch 'origin/develop' into ramirotw/issue-168…
ramirotw Apr 18, 2022
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
1 change: 0 additions & 1 deletion src/custom/components/AffiliateStatusCheck/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ export default function AffiliateStatusCheck() {
return
}

setAffiliateState(null)
setError('')

if (!account) {
Expand Down
11 changes: 8 additions & 3 deletions src/custom/hooks/useParseReferralQueryParam.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { useMemo } from 'react'
import { useMemo, useState } from 'react'
import useParsedQueryString from 'hooks/useParsedQueryString'
import { REFERRAL_QUERY_PARAM } from 'hooks/useReferralLink'
import useENS from 'hooks/useENS'
import { isAddress } from '../utils'
alfetopito marked this conversation as resolved.
Show resolved Hide resolved

type ReferralQueryValue = {
value: string
Expand All @@ -15,9 +16,13 @@ export default function useParseReferralQueryParam(): ReferralQueryValue {
const parsedQs = useParsedQueryString()
const referralAddress = parsedQs[REFERRAL_QUERY_PARAM] as string
const result = useENS(referralAddress)
const [loading, setLoading] = useState(isAddress(referralAddress) === false) // this is a hack to force a initial loading state to true in case of referralAddress is a ens name because the useENS hook returns loading as false when initialized

const referral = useMemo(() => {
if (result.loading || !referralAddress) {
if (loading || result.loading || !referralAddress) {
if (result.loading) {
setLoading(false)
}
return null
}

Expand All @@ -27,7 +32,7 @@ export default function useParseReferralQueryParam(): ReferralQueryValue {

console.warn('Invalid referral address')
return { value: '', isValid: false }
}, [result.loading, result.address, referralAddress])
}, [result.loading, result.address, referralAddress, loading])

return referral
}
18 changes: 15 additions & 3 deletions src/custom/pages/Profile/AddressSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ export default function AddressSelector(props: AddressSelectorProps) {
const node = useRef<HTMLDivElement>(null)
useOnClickOutside(node, open ? toggle : undefined)

const tryShortenAddress = useCallback((item?: string) => {
if (!item) {
return item
}

try {
return shortenAddress(item)
} catch (error) {
return item
}
}, [])

const handleSelectItem = useCallback(
(item: string) => {
dispatch(updateAddress(item))
Expand Down Expand Up @@ -80,19 +92,19 @@ export default function AddressSelector(props: AddressSelectorProps) {
return (
<>
{items.length === 1 ? (
<strong>{address}</strong>
<strong>{tryShortenAddress(address)}</strong>
) : (
<Wrapper ref={node}>
<AddressInfo onClick={toggle}>
<span style={{ marginRight: '2px' }}>{selectedAddress}</span>
<span style={{ marginRight: '2px' }}>{tryShortenAddress(selectedAddress)}</span>
<ChevronDown size={16} style={{ marginTop: '2px' }} strokeWidth={2.5} />
</AddressInfo>
{open && (
<MenuFlyout>
{items.map((item) => (
<ButtonMenuItem key={item} $selected={item === ''} onClick={() => handleSelectItem(item)}>
<GreenCheck size={16} strokeWidth={2.5} $visible={item === selectedAddress} />{' '}
{isAddress(item) ? shortenAddress(item) : item}
{tryShortenAddress(item)}
</ButtonMenuItem>
))}
</MenuFlyout>
Expand Down
4 changes: 2 additions & 2 deletions src/custom/pages/Profile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { RefreshCcw } from 'react-feather'
import Web3Status from 'components/Web3Status'
import useReferralLink from 'hooks/useReferralLink'
import useFetchProfile from 'hooks/useFetchProfile'
import { getBlockExplorerUrl } from 'utils'
import { getBlockExplorerUrl, shortenAddress } from 'utils'
import { formatMax, formatSmartLocaleAware, numberFormatter } from 'utils/format'
import { getExplorerAddressLink } from 'utils/explorer'
import useTimeAgo from 'hooks/useTimeAgo'
Expand Down Expand Up @@ -306,7 +306,7 @@ export default function Profile() {
<span style={{ wordBreak: 'break-all', display: 'inline-block' }}>
{referralLink.prefix}
{chainId === ChainId.XDAI ? (
<strong>{referralLink.address}</strong>
<strong>{shortenAddress(referralLink.address)}</strong>
) : (
<AddressSelector address={referralLink.address} />
)}
Expand Down