-
Notifications
You must be signed in to change notification settings - Fork 505
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
170 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import type { Feature } from './types'; | ||
|
||
import { getEnvValue } from '../utils'; | ||
|
||
const appUrl = getEnvValue('NEXT_PUBLIC_SWAP_BUTTON_URL'); | ||
|
||
const title = 'Swap button'; | ||
|
||
const config: Feature<{ appUrl: string }> = (() => { | ||
if (appUrl) { | ||
return Object.freeze({ | ||
title, | ||
isEnabled: true, | ||
appUrl, | ||
}); | ||
} | ||
|
||
return Object.freeze({ | ||
title, | ||
isEnabled: false, | ||
}); | ||
})(); | ||
|
||
export default config; |
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,7 @@ | ||
import type { NextRouter } from 'next/router'; | ||
|
||
export default function removeQueryParam(router: NextRouter, param: string) { | ||
const { pathname, query } = router; | ||
delete router.query[param]; | ||
router.replace({ pathname, query }, undefined, { shallow: true }); | ||
} |
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,7 @@ | ||
import type { NextRouter } from 'next/router'; | ||
|
||
export default function updateQueryParam(router: NextRouter, param: string, newValue: string) { | ||
const { pathname, query } = router; | ||
query[param] = newValue; | ||
router.replace({ pathname, query }, undefined, { shallow: true }); | ||
} |
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,39 @@ | ||
import { useRouter } from 'next/router'; | ||
import { useEffect, useRef } from 'react'; | ||
|
||
import removeQueryParam from 'lib/router/removeQueryParam'; | ||
import updateQueryParam from 'lib/router/updateQueryParam'; | ||
import useWallet from 'ui/snippets/walletMenu/useWallet'; | ||
|
||
export default function useMarketplaceWallet() { | ||
const router = useRouter(); | ||
const { isWalletConnected, isModalOpen, connect } = useWallet({ source: 'Swap button' }); | ||
const isConnectionStarted = useRef(false); | ||
|
||
useEffect(() => { | ||
if (router.query.action !== 'connect') { | ||
return; | ||
} | ||
|
||
let timer: ReturnType<typeof setTimeout>; | ||
|
||
if (!isWalletConnected && !isModalOpen) { | ||
if (!isConnectionStarted.current) { | ||
timer = setTimeout(() => { | ||
if (!isWalletConnected) { | ||
connect(); | ||
isConnectionStarted.current = true; | ||
} | ||
}, 500); | ||
} else { | ||
isConnectionStarted.current = false; | ||
updateQueryParam(router, 'action', 'tooltip'); | ||
} | ||
} else if (isWalletConnected) { | ||
isConnectionStarted.current = false; | ||
removeQueryParam(router, 'action'); | ||
} | ||
|
||
return () => clearTimeout(timer); | ||
}, [ isWalletConnected, isModalOpen, connect, router ]); | ||
} |
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,35 @@ | ||
import { Button, Box } from '@chakra-ui/react'; | ||
import React from 'react'; | ||
|
||
import { route } from 'nextjs-routes'; | ||
|
||
import * as regexp from 'lib/regexp'; | ||
import IconSvg from 'ui/shared/IconSvg'; | ||
import LinkExternal from 'ui/shared/LinkExternal'; | ||
import LinkInternal from 'ui/shared/LinkInternal'; | ||
|
||
const SwapButton = ({ appUrl }: { appUrl: string }) => { | ||
const button = ( | ||
<Button variant="solid" size="xs" borderRadius="sm" height={ 5 } px={ 1.5 }> | ||
<IconSvg name="swap" boxSize={ 3 } mr={{ base: 0, sm: 1 }}/> | ||
<Box display={{ base: 'none', sm: 'inline' }}> | ||
Swap | ||
</Box> | ||
</Button> | ||
); | ||
|
||
return regexp.URL_PREFIX.test(appUrl) ? ( | ||
<LinkExternal href={ appUrl } hideIcon> | ||
{ button } | ||
</LinkExternal> | ||
) : ( | ||
<LinkInternal | ||
href={ route({ pathname: '/apps/[id]', query: { id: appUrl, action: 'connect' } }) } | ||
display="contents" | ||
> | ||
{ button } | ||
</LinkInternal> | ||
); | ||
}; | ||
|
||
export default React.memo(SwapButton); |
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