-
Notifications
You must be signed in to change notification settings - Fork 834
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Web DNS Resolver for SNS + ENS V2 #4284
Open
mjkid221
wants to merge
1
commit into
coral-xyz:master
Choose a base branch
from
mjkid221:mj/feat-web-dns-resolver-v2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,44 @@ | ||
import { start } from "@coral-xyz/background"; | ||
|
||
import { supportedDomains, urlPatterns } from "../dns-redirects/constants"; | ||
import { redirect } from "../dns-redirects/helpers/tabHelper"; | ||
|
||
start({ | ||
isMobile: false, | ||
}); | ||
|
||
/** | ||
* Resolves domain names in the form of URLs. | ||
*/ | ||
chrome.webNavigation.onBeforeNavigate.addListener( | ||
async (details) => { | ||
await redirect(details.url); | ||
}, | ||
{ | ||
url: supportedDomains.map((domain) => { | ||
return { urlMatches: `^[^:]+://[^/]+.${domain}/.*$` }; | ||
}), | ||
} | ||
); | ||
|
||
/** | ||
* Resolves domain names in the form of browser searches via Google, Bing, etc. | ||
* DuckDuckGo has a unique search pattern and must be queried separately. | ||
*/ | ||
chrome.webNavigation.onBeforeNavigate.addListener( | ||
async (details) => { | ||
const domainUrl = new URL(details.url).searchParams.get("q"); | ||
if (domainUrl && domainUrl.indexOf(" ") < 0) await redirect(domainUrl); | ||
}, | ||
{ | ||
url: supportedDomains.flatMap((param) => | ||
urlPatterns.map((pattern) => { | ||
return { | ||
urlMatches: pattern.includes("duckduckgo") | ||
? `${pattern}\\.${param}$` | ||
: `${pattern}\\.${param}&.*$`, | ||
}; | ||
}) | ||
), | ||
} | ||
); |
60 changes: 60 additions & 0 deletions
60
...sion/src/components/Unlocked/Settings/Preferences/WebDomainResolver/CustomIpfsGateway.tsx
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,60 @@ | ||
import { useState } from "react"; | ||
import { UI_RPC_METHOD_SETTINGS_DOMAIN_CONTENT_IPFS_GATEWAY_UPDATE } from "@coral-xyz/common"; | ||
import { useTranslation } from "@coral-xyz/i18n"; | ||
import { InputListItem, Inputs, PrimaryButton } from "@coral-xyz/react-common"; | ||
import { useBackgroundClient } from "@coral-xyz/recoil"; | ||
|
||
import { setIPFSGateway } from "../../../../../dns-redirects/helpers"; | ||
|
||
export function PreferencesCustomIpfsGateway() { | ||
const background = useBackgroundClient(); | ||
const { t } = useTranslation(); | ||
|
||
const [gatewayUrl, setGatewayUrl] = useState(""); | ||
const changeIpfsGateway = async () => { | ||
try { | ||
background | ||
.request({ | ||
method: UI_RPC_METHOD_SETTINGS_DOMAIN_CONTENT_IPFS_GATEWAY_UPDATE, | ||
params: [gatewayUrl], | ||
}) | ||
.catch(console.error); | ||
|
||
await setIPFSGateway(gatewayUrl); | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
}; | ||
|
||
return ( | ||
<div style={{ paddingTop: "16px", height: "100%" }}> | ||
<form | ||
onSubmit={changeIpfsGateway} | ||
style={{ display: "flex", height: "100%", flexDirection: "column" }} | ||
> | ||
<div style={{ flex: 1, flexGrow: 1 }}> | ||
<Inputs error={false}> | ||
<InputListItem | ||
isFirst | ||
isLast | ||
button={false} | ||
title={t("gateway")} | ||
placeholder={t("gateway_url")} | ||
value={gatewayUrl} | ||
onChange={(e) => { | ||
setGatewayUrl(e.target.value); | ||
}} | ||
/> | ||
</Inputs> | ||
</div> | ||
<div style={{ padding: 16 }}> | ||
<PrimaryButton | ||
disabled={!gatewayUrl} | ||
label={t("switch")} | ||
type="submit" | ||
/> | ||
</div> | ||
</form> | ||
</div> | ||
); | ||
} |
73 changes: 73 additions & 0 deletions
73
...sion/src/components/Unlocked/Settings/Preferences/WebDomainResolver/SwitchIpfsGateway.tsx
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,73 @@ | ||
import { | ||
DEFAULT_IPFS_GATEWAYS, | ||
UI_RPC_METHOD_SETTINGS_DOMAIN_CONTENT_IPFS_GATEWAY_UPDATE, | ||
} from "@coral-xyz/common"; | ||
import { useTranslation } from "@coral-xyz/i18n"; | ||
import { PushDetail } from "@coral-xyz/react-common"; | ||
import { useBackgroundClient, useIpfsGateway } from "@coral-xyz/recoil"; | ||
import { useNavigation } from "@react-navigation/native"; | ||
|
||
import { setIPFSGateway } from "../../../../../dns-redirects/helpers"; | ||
import { Routes } from "../../../../../refactor/navigation/SettingsNavigator"; | ||
import { SettingsList } from "../../../../common/Settings/List"; | ||
import { Checkmark } from "../Blockchains/ConnectionSwitch"; | ||
|
||
interface MenuItems { | ||
[key: string]: { | ||
onClick: () => void; | ||
detail?: React.ReactNode; | ||
style?: React.CSSProperties; | ||
classes?: any; | ||
button?: boolean; | ||
icon?: React.ReactNode; | ||
label?: string; | ||
}; | ||
} | ||
export function PreferencesIpfsGateway() { | ||
const background = useBackgroundClient(); | ||
const { t } = useTranslation(); | ||
|
||
const navigation = useNavigation<any>(); | ||
|
||
const currentIpfsGatewayUrl = useIpfsGateway(); | ||
const changeIpfsGateway = async (url: string) => { | ||
try { | ||
background | ||
.request({ | ||
method: UI_RPC_METHOD_SETTINGS_DOMAIN_CONTENT_IPFS_GATEWAY_UPDATE, | ||
params: [url], | ||
}) | ||
.catch(console.error); | ||
await setIPFSGateway(url); | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
}; | ||
|
||
const menuItems = DEFAULT_IPFS_GATEWAYS.reduce((acc, gateway) => { | ||
(acc as MenuItems)[gateway] = { | ||
onClick: () => changeIpfsGateway(gateway), | ||
detail: currentIpfsGatewayUrl === gateway && <Checkmark />, | ||
}; | ||
return acc; | ||
}, {}); | ||
const customMenu: MenuItems = { | ||
[t("custom")]: { | ||
onClick: () => | ||
navigation.push( | ||
Routes.PreferencesWebDomainResolverIpfsGatewayCustomScreen | ||
), | ||
detail: !DEFAULT_IPFS_GATEWAYS.includes(currentIpfsGatewayUrl) ? ( | ||
<> | ||
<Checkmark /> | ||
<PushDetail /> | ||
</> | ||
) : ( | ||
<PushDetail /> | ||
), | ||
}, | ||
}; | ||
Object.assign(menuItems, customMenu); | ||
|
||
return <SettingsList menuItems={menuItems} />; | ||
} |
120 changes: 120 additions & 0 deletions
120
...es/app-extension/src/components/Unlocked/Settings/Preferences/WebDomainResolver/index.tsx
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,120 @@ | ||
import { | ||
Blockchain, | ||
UI_RPC_METHOD_SETTINGS_DOMAIN_RESOLUTION_NETWORKS_UPDATE, | ||
} from "@coral-xyz/common"; | ||
import { useTranslation } from "@coral-xyz/i18n"; | ||
import { | ||
getBlockchainLogo, | ||
useBackgroundClient, | ||
useSupportedDnsNetwork, | ||
} from "@coral-xyz/recoil"; | ||
import { useNavigation } from "@react-navigation/native"; | ||
|
||
import { toggleSupportedNetworkResolution } from "../../../../../dns-redirects/helpers"; | ||
import { Routes } from "../../../../../refactor/navigation/SettingsNavigator"; | ||
import { SettingsList } from "../../../../common/Settings/List"; | ||
import { ModeSwitch } from ".."; | ||
|
||
export const PreferencesDomainResolverContent: React.FC = () => { | ||
const { t } = useTranslation(); | ||
|
||
const navigation = useNavigation<any>(); | ||
const resolverMenuItems = { | ||
[t("ipfs_gateways")]: { | ||
onClick: () => | ||
navigation.push(Routes.PreferencesWebDomainResolverIpfsGatewayScreen), | ||
}, | ||
}; | ||
|
||
const background = useBackgroundClient(); | ||
|
||
const isSupportedNetwork = { | ||
[Blockchain.SOLANA]: useSupportedDnsNetwork(Blockchain.SOLANA), | ||
[Blockchain.ETHEREUM]: useSupportedDnsNetwork(Blockchain.ETHEREUM), | ||
}; | ||
|
||
const toggleSupportedDNSResolutionNetworks = async ( | ||
blockchain: Blockchain, | ||
isEnabled: boolean | ||
) => { | ||
try { | ||
background | ||
.request({ | ||
method: UI_RPC_METHOD_SETTINGS_DOMAIN_RESOLUTION_NETWORKS_UPDATE, | ||
params: [blockchain, isEnabled], | ||
}) | ||
.catch(console.error); | ||
await toggleSupportedNetworkResolution(blockchain, isEnabled); | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
}; | ||
|
||
const blockchainMenuItems: any = { | ||
Solana: { | ||
onClick: async () => { | ||
await toggleSupportedDNSResolutionNetworks( | ||
Blockchain.SOLANA, | ||
!isSupportedNetwork[Blockchain.SOLANA] | ||
); | ||
}, | ||
icon: () => { | ||
const blockchainLogo = getBlockchainLogo(Blockchain.SOLANA); | ||
return ( | ||
<img | ||
src={blockchainLogo} | ||
style={{ | ||
width: "12px", | ||
height: "12px", | ||
marginRight: "8px", | ||
}} | ||
/> | ||
); | ||
}, | ||
detail: ( | ||
<ModeSwitch | ||
enabled={isSupportedNetwork[Blockchain.SOLANA]} | ||
onSwitch={(enabled) => | ||
toggleSupportedDNSResolutionNetworks(Blockchain.SOLANA, enabled) | ||
} | ||
/> | ||
), | ||
}, | ||
Ethereum: { | ||
onClick: async () => { | ||
await toggleSupportedDNSResolutionNetworks( | ||
Blockchain.ETHEREUM, | ||
!isSupportedNetwork[Blockchain.ETHEREUM] | ||
); | ||
}, | ||
icon: () => { | ||
const blockchainLogo = getBlockchainLogo(Blockchain.ETHEREUM); | ||
return ( | ||
<img | ||
src={blockchainLogo} | ||
style={{ | ||
width: "12px", | ||
height: "12px", | ||
marginRight: "8px", | ||
}} | ||
/> | ||
); | ||
}, | ||
detail: ( | ||
<ModeSwitch | ||
enabled={isSupportedNetwork[Blockchain.ETHEREUM]} | ||
onSwitch={(enabled) => | ||
toggleSupportedDNSResolutionNetworks(Blockchain.ETHEREUM, enabled) | ||
} | ||
/> | ||
), | ||
}, | ||
}; | ||
|
||
return ( | ||
<div> | ||
<SettingsList menuItems={resolverMenuItems} /> | ||
<SettingsList menuItems={blockchainMenuItems as any} /> | ||
</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
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,38 @@ | ||
<div id="main"> | ||
<div class="fof"> | ||
<text>Redirect Error</text> | ||
<h1>404</h1> | ||
<text>Your domain was unavailable.</text> | ||
</div> | ||
</div> | ||
<style> | ||
html { | ||
height: 100%; | ||
} | ||
|
||
body { | ||
font-family: "Lato", sans-serif; | ||
color: #888; | ||
margin: 0; | ||
background-color: #111; | ||
} | ||
|
||
#main { | ||
display: table; | ||
width: 100%; | ||
height: 100vh; | ||
text-align: center; | ||
} | ||
|
||
.fof { | ||
display: table-cell; | ||
vertical-align: middle; | ||
} | ||
|
||
.fof h1 { | ||
font-size: 50px; | ||
display: inline-block; | ||
padding-right: 12px; | ||
padding-left: 12px; | ||
} | ||
</style> |
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.
Instead of having two separate chrome.webNavigation.onBeforeNavigate event listeners, we can combine them into one to reduce redundancy.
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.
just a suggestion, please verify on your own.
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.
I have put an suggestion for the change in whole file for this