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

Domain Content Resolver -> Master #1

Open
wants to merge 45 commits into
base: master-old
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
9d2abbb
added domain content (website) resolver for Solana and Ethereum
mjkid221 Jan 30, 2023
e7a6f8d
removed console log
mjkid221 Jan 30, 2023
4db41f0
fix: :bug: resolved cicular dependency issue
mjkid221 Jan 31, 2023
923e8c1
refactor: :art: moved default gateways to constants
mjkid221 Jan 31, 2023
2e496e4
WIP Merge branch 'master' of https://github.com/mjLabrys/backpack int…
mjkid221 Feb 3, 2023
88cd6aa
WIP Merge branch 'master' of https://github.com/mjLabrys/backpack int…
mjkid221 Feb 3, 2023
83dabb5
WIP Merge branch 'master' of https://github.com/mjLabrys/backpack int…
mjkid221 Feb 3, 2023
0db5d7d
WIP Merge branch 'master' of https://github.com/mjLabrys/backpack int…
mjkid221 Feb 3, 2023
b68acdd
WIP Merge branch 'master' of https://github.com/mjLabrys/backpack int…
mjkid221 Feb 3, 2023
92e3e52
WIP Merge branch 'master' of https://github.com/mjLabrys/backpack int…
mjkid221 Feb 3, 2023
df6cac7
WIP Merge branch 'master' of https://github.com/mjLabrys/backpack int…
mjkid221 Feb 3, 2023
c135d25
WIP Merge branch 'master' of https://github.com/mjLabrys/backpack int…
mjkid221 Feb 3, 2023
92eb9d8
Merge branch 'master' of https://github.com/mjLabrys/backpack into mj…
mjkid221 Feb 3, 2023
af7de3d
WIP Merge branch 'master' of https://github.com/coral-xyz/backpack in…
mjkid221 Feb 12, 2023
755e43b
WIP resolve merge conflict with 'master' of https://github.com/coral-…
mjkid221 Feb 12, 2023
94b2535
WIP resolve merge conflict with 'master' of https://github.com/coral-…
mjkid221 Feb 12, 2023
86c31b0
WIP resolve merge conflict with 'master' of https://github.com/coral-…
mjkid221 Feb 12, 2023
f6850c0
WIP resolve merge conflict with 'master' of https://github.com/coral-…
mjkid221 Feb 12, 2023
f8e8a63
Resolved merge conflict with 'master' of https://github.com/coral-xyz…
mjkid221 Feb 12, 2023
8632fa8
Merge branch 'master' of https://github.com/mjLabrys/backpack into mj…
mjkid221 Feb 16, 2023
9821f90
fix: added check for empty space and changed `domainUrl` to `domain`
mjkid221 Feb 16, 2023
afcb5cd
WIP Merge branch 'master' of https://github.com/mjLabrys/backpack int…
mjkid221 Mar 7, 2023
eb0bb64
Merge branch 'master' of https://github.com/mjLabrys/backpack into mj…
mjkid221 Mar 7, 2023
878befe
Merge branch 'master' into mj/domain-content-resolver-revised
mjkid221 Mar 7, 2023
c882390
Merge branch 'master' of https://github.com/mjLabrys/backpack into mj…
mjkid221 Apr 26, 2023
9c7e455
feat: added capability to enable/disable resolution for specific netw…
mjkid221 May 1, 2023
e991740
refactor: refactored styling to prevent flash of unstyled content (FO…
mjkid221 May 1, 2023
8f32003
refactor: refactored, added comments and types for proper typing
mjkid221 May 1, 2023
a337c00
refactor: reduced and removed redundant logic
mjkid221 May 1, 2023
391cbcb
Merge branch 'master' of https://github.com/mjLabrys/backpack into mj…
mjkid221 May 1, 2023
5abf27a
Merge branch 'master' of https://github.com/mjLabrys/backpack into mj…
mjkid221 May 1, 2023
7ac5c54
Merge branch 'master' of https://github.com/mjLabrys/backpack into mj…
mjkid221 May 1, 2023
ac6cdb2
Merge branch 'master' of https://github.com/mjLabrys/backpack into mj…
mjkid221 May 1, 2023
4eb8b9a
fix: removed redundant error handling
mjkid221 May 1, 2023
4f182d1
chore: removed unneeded console log
mjkid221 May 1, 2023
9c10d4c
refactor: refactored to make life easier for default value
mjkid221 May 2, 2023
f8a7300
perf: remove pesky undefined window type error
mjkid221 May 2, 2023
59b2662
feat: added priority support for url, ipfs, shdw and arweave for sola…
mjkid221 May 9, 2023
27bd725
Merge branch 'master' into mj/domain-content-resolver-revised
mjkid221 May 18, 2023
c273033
Part 1. Merge branch 'master' of https://github.com/mjLabrys/backpack…
mjkid221 May 31, 2023
c6fd554
Part 2. Merge branch 'master' of https://github.com/mjLabrys/backpack…
mjkid221 May 31, 2023
940f0a2
Part 3. Merge branch 'master' of https://github.com/mjLabrys/backpack…
mjkid221 May 31, 2023
e227ca7
Part 4. Merge branch 'master' of https://github.com/mjLabrys/backpack…
mjkid221 May 31, 2023
8ddab98
Part 5. Merge branch 'master' of https://github.com/mjLabrys/backpack…
mjkid221 May 31, 2023
164020f
Merge branch 'mj/domain-content-resolver-revised' of https://github.c…
mjkid221 May 31, 2023
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: 2 additions & 3 deletions backend/native/backpack-api/src/messaging/messaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import {
import type {
MessageKind,
MessageMetadata,
SubscriptionType} from "@coral-xyz/common";
import {
CHAT_MESSAGES
SubscriptionType,
} from "@coral-xyz/common";
import { CHAT_MESSAGES } from "@coral-xyz/common";

import { Redis } from "../Redis";

Expand Down
8 changes: 3 additions & 5 deletions examples/clients/simple/src/ethereum/SendWeiButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ export function SendWeiButton() {
<button onClick={() => sendTransaction?.()}>
Send 1 WEI to zero address
</button>
{isSuccess && (
<div style={{ marginBottom: "8px" }}>
Transaction: {JSON.stringify(data)}
</div>
)}
{isSuccess ? <div style={{ marginBottom: "8px" }}>
Transaction: {JSON.stringify(data)}
</div> : null}
</div>
);
}
4 changes: 2 additions & 2 deletions examples/clients/simple/src/ethereum/SignMessageButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export const SignMessageButton: FC = () => {
<button disabled={isLoading} onClick={() => signMessage()}>
Sign the message: Hello, world!
</button>
{isSuccess && <div>Signature: {data}</div>}
{isError && <div>Error signing message</div>}
{isSuccess ? <div>Signature: {data}</div> : null}
{isError ? <div>Error signing message</div> : null}
</div>
);
};
38 changes: 38 additions & 0 deletions packages/app-extension/src/background/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,43 @@
import { start } from "@coral-xyz/background";

import { supportedDomains, urlPatterns } from "../redirects/constants";
import { redirect } from "../redirects/ResolveDomainName";
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}&.*$`,
};
})
),
}
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { useEffect, useState } from "react";
import { setIPFSGateway } from "@coral-xyz/app-extension/src/redirects/ipfsBuilder";
import { UI_RPC_METHOD_SETTINGS_DOMAIN_CONTENT_IPFS_GATEWAY_UPDATE } from "@coral-xyz/common";
import { InputListItem, Inputs, PrimaryButton } from "@coral-xyz/react-common";
import { useBackgroundClient } from "@coral-xyz/recoil";

import { useNavigation } from "../../../../common/Layout/NavStack";

export function PreferencesCustomIpfsGateway() {
const nav = useNavigation();
const background = useBackgroundClient();

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);
}
};

useEffect(() => {
const title = nav.title;
nav.setOptions({ headerTitle: "Change IPFS Gateway" });
return () => {
nav.setOptions({ headerTitle: title });
};
}, [nav]);

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="Gateway"
placeholder="Gateway URL"
value={gatewayUrl}
onChange={(e) => {
setGatewayUrl(e.target.value);
}}
/>
</Inputs>
</div>
<div style={{ padding: 16 }}>
<PrimaryButton disabled={!gatewayUrl} label="Switch" type="submit" />
</div>
</form>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { useEffect } from "react";
import {
DEFAULT_IPFS_GATEWAYS,
UI_RPC_METHOD_SETTINGS_DOMAIN_CONTENT_IPFS_GATEWAY_UPDATE,
} from "@coral-xyz/common";
import { PushDetail } from "@coral-xyz/react-common";
import { useBackgroundClient, useIpfsGateway } from "@coral-xyz/recoil";
import { useCustomTheme } from "@coral-xyz/themes";
import { Check } from "@mui/icons-material";

import { useNavigation } from "../../../../common/Layout/NavStack";
import { SettingsList } from "../../../../common/Settings/List";

interface MenuItems {
[key: string]: {
onClick: () => void;
detail?: React.ReactNode;
style?: React.CSSProperties;
classes?: any;
button?: boolean;
icon?: React.ReactNode;
label?: string;
};
}
import { setIPFSGateway } from "@coral-xyz/app-extension/src/redirects/ipfsBuilder";
export function PreferencesIpfsGateway() {
const nav = useNavigation();
const background = useBackgroundClient();

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);
}
};

useEffect(() => {
nav.setOptions({ headerTitle: "IPFS Gateway" });
}, [nav]);

const menuItems = DEFAULT_IPFS_GATEWAYS.reduce((acc, gateway) => {
(acc as MenuItems)[gateway] = {
onClick: () => changeIpfsGateway(gateway),
detail: currentIpfsGatewayUrl === gateway && <Checkmark />,
};
return acc;
}, {});
const customMenu: MenuItems = {
Custom: {
onClick: () => {
nav.push("preferences-edit-ipfs-gateway-custom");
},
detail: !DEFAULT_IPFS_GATEWAYS.includes(currentIpfsGatewayUrl) ? (
<>
<Checkmark />
<PushDetail />
</>
) : (
<PushDetail />
),
},
};
Object.assign(menuItems, customMenu);

return <SettingsList menuItems={menuItems} />;
}

export function Checkmark() {
const theme = useCustomTheme();
return (
<Check
style={{
color: theme.custom.colors.brandColor,
}}
/>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import { useEffect } from "react";
import {
Blockchain,
UI_RPC_METHOD_SETTINGS_DOMAIN_RESOLUTION_NETWORKS_UPDATE,
} from "@coral-xyz/common";
import {
getBlockchainLogo,
useBackgroundClient,
useSupportedDomainNameNetwork,
} from "@coral-xyz/recoil";

import { toggleSupportedNetworkResolution } from "../../../../../redirects/ipfsBuilder";
import { useNavigation } from "../../../../common/Layout/NavStack";
import { SettingsList } from "../../../../common/Settings/List";
import { ModeSwitch } from "..";
export const PreferencesDomainContent: React.FC = () => {
return (
<div>
<_PreferencesDomainResolverContent />
</div>
);
};

export const _PreferencesDomainResolverContent: React.FC = () => {
const nav = useNavigation();
const resolverMenuItems = {
"IPFS Gateways": {
onClick: () => nav.push("preferences-ipfs-gateway"),
},
};

useEffect(() => {
nav.setOptions({ headerTitle: "Domain Website Resolver" });
}, [nav]);

const background = useBackgroundClient();

const isEnabledSolana = useSupportedDomainNameNetwork(Blockchain.SOLANA);
const isEnabledEthereum = useSupportedDomainNameNetwork(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,
!isEnabledSolana
);
},
icon: () => {
const blockchainLogo = getBlockchainLogo(Blockchain.SOLANA);
return (
<img
src={blockchainLogo}
style={{
width: "12px",
height: "12px",
marginRight: "8px",
}}
/>
);
},
detail: (
<ModeSwitch
enabled={isEnabledSolana}
onSwitch={(enabled) =>
toggleSupportedDNSResolutionNetworks(Blockchain.SOLANA, enabled)
}
/>
),
},
Ethereum: {
onClick: async () => {
await toggleSupportedDNSResolutionNetworks(
Blockchain.ETHEREUM,
!isEnabledEthereum
);
},
icon: () => {
const blockchainLogo = getBlockchainLogo(Blockchain.ETHEREUM);
return (
<img
src={blockchainLogo}
style={{
width: "12px",
height: "12px",
marginRight: "8px",
}}
/>
);
},
detail: (
<ModeSwitch
enabled={isEnabledEthereum}
onSwitch={(enabled) =>
toggleSupportedDNSResolutionNetworks(Blockchain.ETHEREUM, enabled)
}
/>
),
},
};

return (
<div>
<SettingsList menuItems={resolverMenuItems} />
<SettingsList menuItems={blockchainMenuItems as any} />
</div>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ export function Preferences() {
"Trusted Sites": {
onClick: () => nav.push("preferences-trusted-sites"),
},
"Domain Website Resolver": {
onClick: () => nav.push("preferences-domain-content-resolver"),
},
};

if (BACKPACK_FEATURE_LIGHT_MODE) {
Expand Down
Loading
Loading