-
Notifications
You must be signed in to change notification settings - Fork 0
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
[NFT-740] wip: swap widget #264
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
db2d0c8
chore: add uniswap widgets
cnasc 888fa47
fix: remove forbidden non-null
cnasc 1f3681e
wip: trying to get swap widget to work
cnasc 45c5e47
fix: add missing deps
cnasc 7610787
wip: latest
cnasc 3b9d17b
fix: use signer?.provider
cnasc 2766d42
fix: better type-safe provider
cnasc a076d4b
chore: header now links to swap page
cnasc 41fe5c5
feat: customize tokens
cnasc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,7 @@ | ||
.wrapper { | ||
display: flex; | ||
width: 100%; | ||
height: 100%; | ||
align-items: center; | ||
justify-content: center; | ||
} |
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,65 @@ | ||
import { JsonRpcSigner } from '@ethersproject/providers'; | ||
import { SwapWidget, Theme } from '@uniswap/widgets'; | ||
import '@uniswap/widgets/fonts.css'; | ||
import { useConfig } from 'hooks/useConfig'; | ||
import { useController } from 'hooks/useController'; | ||
import { useMemo } from 'react'; | ||
import { useSigner } from 'wagmi'; | ||
import styles from './SwapPageContent.module.css'; | ||
|
||
const theme: Theme = { | ||
primary: '#000', | ||
secondary: '#000', | ||
interactive: '#C6E6E1', | ||
container: '#FFF', | ||
module: '#F2F9F8', | ||
accent: '#0000EE', | ||
outline: '#000', | ||
dialog: '#000', | ||
fontFamily: 'Courier Prime', | ||
borderRadius: 0.5, | ||
}; | ||
|
||
export function SwapPageContent() { | ||
const { paprToken, underlying } = useController(); | ||
const { chainId, jsonRpcProvider, tokenName } = useConfig(); | ||
const provider = useSigner<JsonRpcSigner>().data?.provider; | ||
|
||
const jsonRpcUrlMap = useMemo( | ||
() => ({ [chainId]: jsonRpcProvider }), | ||
[chainId, jsonRpcProvider], | ||
); | ||
|
||
const tokenList = useMemo( | ||
() => [ | ||
{ | ||
address: underlying.id, | ||
chainId, | ||
decimals: underlying.decimals, | ||
name: 'USD Coin', | ||
symbol: 'USDC', | ||
}, | ||
{ | ||
address: paprToken.id, | ||
chainId, | ||
decimals: paprToken.decimals, | ||
name: tokenName, | ||
symbol: tokenName, | ||
}, | ||
], | ||
[chainId, paprToken, tokenName, underlying], | ||
); | ||
|
||
return ( | ||
<div className={styles.wrapper}> | ||
<SwapWidget | ||
theme={theme} | ||
jsonRpcUrlMap={jsonRpcUrlMap} | ||
provider={provider} | ||
tokenList={tokenList} | ||
defaultInputTokenAddress={paprToken.id} | ||
defaultOutputTokenAddress={underlying.id} | ||
/> | ||
</div> | ||
); | ||
} |
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 @@ | ||
export { SwapPageContent } from './SwapPageContent'; |
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 |
---|---|---|
@@ -1,38 +1,56 @@ | ||
import { GetServerSideProps } from 'next'; | ||
import React from 'react'; | ||
import { captureException } from '@sentry/nextjs'; | ||
import { SupportedToken, validateToken } from 'lib/config'; | ||
import { configs, getConfig, SupportedToken } from 'lib/config'; | ||
import { OpenGraph } from 'components/OpenGraph'; | ||
import capitalize from 'lodash/capitalize'; | ||
import { SwapPageContent } from 'components/SwapPageContent'; | ||
import { fetchSubgraphData, SubgraphController } from 'lib/PaprController'; | ||
import { ControllerContextProvider } from 'hooks/useController'; | ||
|
||
export const getServerSideProps: GetServerSideProps<SwapProps> = async ( | ||
context, | ||
) => { | ||
try { | ||
validateToken(context.params!); | ||
const token = context.params?.token as SupportedToken; | ||
|
||
return { | ||
props: { | ||
token, | ||
}, | ||
}; | ||
} catch (e) { | ||
captureException(e); | ||
const token = context.params?.token as SupportedToken; | ||
const address: string | undefined = | ||
getConfig(token)?.controllerAddress?.toLocaleLowerCase(); | ||
if (!address) { | ||
return { | ||
notFound: true, | ||
}; | ||
} | ||
|
||
const controllerSubgraphData = await fetchSubgraphData( | ||
address, | ||
configs[token].uniswapSubgraph, | ||
token, | ||
); | ||
|
||
if (!controllerSubgraphData) { | ||
const e = new Error(`subgraph data for controller ${address} not found`); | ||
captureException(e); | ||
throw e; | ||
} | ||
|
||
const { paprController } = controllerSubgraphData; | ||
|
||
return { | ||
props: { | ||
subgraphController: paprController, | ||
token, | ||
}, | ||
}; | ||
}; | ||
|
||
type SwapProps = { | ||
token: SupportedToken; | ||
subgraphController: SubgraphController; | ||
}; | ||
export default function Swap({ token }: SwapProps) { | ||
export default function Swap({ subgraphController, token }: SwapProps) { | ||
return ( | ||
<> | ||
<ControllerContextProvider value={subgraphController}> | ||
<OpenGraph title={`Backed | ${capitalize(token)} | Swap`} /> | ||
<h1>under construction</h1> | ||
</> | ||
<SwapPageContent /> | ||
</ControllerContextProvider> | ||
); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need to include this in deps? noticed its not imported anywhere, same with qs below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see: Uniswap/widgets#374