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

173 Updates TZP dapp to sanitize network type at all possible inputs,… #173

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 4 additions & 2 deletions dapp/src/routes/Search/Search.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import { useNavigate } from 'svelte-navigator';
import { onMount } from 'svelte';
import { defaultSearchOpts, search, network, alert } from 'src/store';
import type NetworkType from 'enumsNetworkType';
import NetworkType from 'enums/NetworkType';
import { findAddressFromDomain } from './searchHelper';
import './search.scss';

Expand All @@ -32,7 +32,9 @@
};

const setSelectedNetwork = () => {
network.set(localNetwork as NetworkType);
if (Object.values(NetworkType).includes(localNetwork as NetworkType)) {
network.set(localNetwork as NetworkType);
}
};

const searchProfiles = async () => {
Expand Down
12 changes: 8 additions & 4 deletions dapp/src/routes/View.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
search,
network,
} from 'src/store';
import type NetworkType from 'enumsNetworkType';
import NetworkType from 'enums/NetworkType';
import { BasePage, LoadingSpinner, PublicProfileView } from 'components';

const params = useParams();
Expand All @@ -21,9 +21,13 @@
onMount(() => {
// TODO: Generalize over claim types?
if (!$searchClaims?.basic.content || !$searchClaims?.twitter.content) {
network.set(
($params.network as NetworkType) || ('mainnet' as NetworkType)
);
const n = $params.network;
if (Object.values(NetworkType).includes(n as NetworkType)) {
network.set(n as NetworkType);
} else {
network.set(NetworkType.MAINNET)
}

fetching = true;
search($params.address, defaultSearchOpts).finally(() => {
fetching = false;
Expand Down
17 changes: 11 additions & 6 deletions dapp/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,13 @@ wallet.subscribe((w) => {
}
});

network.subscribe((network) => {
if (network === NetworkType.CUSTOM) {
network.subscribe((n) => {
if (!Object.values(NetworkType).includes(n as NetworkType)) {
network.set(NetworkType.MAINNET)
return
}

if (n === NetworkType.CUSTOM) {
networkStr.set('custom');
// TODO can't read from writeable, but then I don't understand why others work.
networkStrTemp = 'custom';
Expand All @@ -404,12 +409,12 @@ network.subscribe((network) => {
tzktBaseTemp = 'http://localhost:5000';
tzktBase.set(tzktBaseTemp);
} else {
networkStr.set(network);
networkStr.set(n);
// TODO can't read from writeable, but then I don't understand why others work.
networkStrTemp = network;
strNetwork = network;
networkStrTemp = n;
strNetwork = n;

urlNode = `https://${network}.api.tez.ie/`;
urlNode = `https://${n}.api.tez.ie/`;
nodeUrl.set(urlNode);

tzktBaseTemp = `https://api.${networkStrTemp}.tzkt.io`;
Expand Down
Loading