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

feat(taikoon): geoblocking #17201

Merged
merged 49 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
b901610
geo-blocking polished
bearni95 May 2, 2024
beb3b55
Merge branch 'main' into feat/blacklisting-and-geoblocking
bearni95 May 13, 2024
5a35f81
swapping branches
bearni95 May 13, 2024
69385f8
smart contract blacklist, with scripts and tests
bearni95 May 13, 2024
720782d
Merge branch 'main' into feat/blacklisting-and-geoblocking
bearni95 May 13, 2024
ec58e1c
Typo fix
bearni95 May 13, 2024
2569ba1
Merge branch 'main' into feat/blacklisting-and-geoblocking
bearni95 May 15, 2024
7b155df
reverted leftook changes
bearni95 May 15, 2024
ccb339f
reverted taikoon package changes for blacklist
bearni95 May 15, 2024
b336370
reverted changes to autogenerated code
bearni95 May 15, 2024
80a36fc
updated routes to geoblock the whole site
bearni95 May 15, 2024
6d64a4a
debug info
bearni95 May 15, 2024
01f2da0
vercel ip country detection extended debug info
bearni95 May 15, 2024
e0f09b0
Merge branch 'main' into feat/geoblocking
bearni95 May 15, 2024
8a229ba
Merge branch 'main' into feat/geoblocking
bearni95 May 16, 2024
803a178
extended svelte options
bearni95 May 16, 2024
3327014
pnpm-lock.yaml
bearni95 May 16, 2024
26f2a9d
Merge branch 'main' into feat/geoblocking
bearni95 May 16, 2024
6022f3d
testing with vercel's package
bearni95 May 16, 2024
c857b45
format & lint
bearni95 May 16, 2024
2fc07cd
svelte config tweaks
bearni95 May 16, 2024
f01caa4
pnpm-lock.yaml
bearni95 May 16, 2024
c478824
enabled ssr on taikoons for geolocation headers test
bearni95 May 16, 2024
bdcb271
removed geolocation specific check and reverted to headers
bearni95 May 16, 2024
0619bf2
added server specific render handler
bearni95 May 16, 2024
b039e63
removed client side page handler
bearni95 May 16, 2024
304ef5c
trying api endpoint for geolocation
bearni95 May 16, 2024
8bba18f
coordinated server and client location rendering
bearni95 May 16, 2024
642202e
throw error on invalid country detected
bearni95 May 16, 2024
7a5e512
added missing import
bearni95 May 16, 2024
bff680e
added alert for location
bearni95 May 16, 2024
4e462bf
Merge branch 'main' into feat/geoblocking
bearni95 May 16, 2024
ccc2ecc
error page handler
bearni95 May 16, 2024
3b5a4ca
testing reversely, as VPN won't connect from banned countries
bearni95 May 16, 2024
62f15ca
added US to banned countries
bearni95 May 16, 2024
e192792
fixed svelte:check error
bearni95 May 16, 2024
fbccfd4
simplified server handling for non-allowed countries
bearni95 May 16, 2024
f03e684
clean commit, lgtm
bearni95 May 16, 2024
0276255
replaced sveltejs/adapter-svelte with adapter-auto; brought back chai…
bearni95 May 16, 2024
a76abef
pnpm-lock.yaml
bearni95 May 16, 2024
9031b1d
corrections
bearni95 May 16, 2024
558b779
Update packages/taikoon-ui/src/routes/+layout.ts
bearni95 May 17, 2024
c25765c
Merge branch 'main' into feat/geoblocking
bearni95 May 17, 2024
bd8c7f5
Merge branch 'main' into feat/geoblocking
bearni95 May 17, 2024
b27b3b7
Merge branch 'main' into feat/geoblocking
KorbinianK May 18, 2024
1104158
Merge branch 'main' into feat/geoblocking
bearni95 May 20, 2024
1c80f9c
included banned countries on error page; cleanup
bearni95 May 20, 2024
2af9abd
Merge branch 'main' into feat/geoblocking
bearni95 May 20, 2024
94bef06
Merge branch 'main' into feat/geoblocking
bearni95 May 20, 2024
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
2 changes: 1 addition & 1 deletion packages/taikoon-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@playwright/test": "^1.28.1",
"@sveltejs/adapter-auto": "^3.0.0",
"@sveltejs/kit": "^2.0.0",
"@sveltejs/vite-plugin-svelte": "^3.0.0",
"@sveltejs/vite-plugin-svelte": "^3.1.0",
"@types/eslint": "^8.56.0",
"@types/jest": "^29.5.12",
"@types/node": "^20.12.7",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,26 +74,27 @@
<h3 class={titleClasses}>{$t('switch_modal.title')}</h3>
<p class={textClasses}>{$t('switch_modal.description')}</p>
<ul role="menu" class=" w-full">
{#each chains as chain (chain.id)}
{@const icon = getChainImage(Number(chain.id)) || 'Unknown Chain'}
{#if chains !== undefined}
{#each chains as chain (chain.id)}
{@const icon = getChainImage(Number(chain.id)) || 'Unknown Chain'}

<li
role="menuitem"
tabindex="0"
class={chainItemClasses}
on:click={() => selectChain(chain)}
on:keydown={getChainKeydownHandler(chain)}>
<!-- TODO: agree on hover:bg color -->
<div class={chainItemContentClasses}>
<div class={chainItemContentWrapperClasses}>
<i role="img" aria-label={chain.name}>
<img src={icon} alt="chain-logo" class="rounded-full" width="30px" height="30px" />
</i>
<span class="body-bold">{chain.name}</span>
<li
role="menuitem"
tabindex="0"
class={chainItemClasses}
on:click={() => selectChain(chain)}
on:keydown={getChainKeydownHandler(chain)}>
<!-- TODO: agree on hover:bg color -->
<div class={chainItemContentClasses}>
<div class={chainItemContentWrapperClasses}>
<i role="img" aria-label={chain.name}>
<img src={icon} alt="chain-logo" class="rounded-full" width="30px" height="30px" />
</i>
<span class="body-bold">{chain.name}</span>
</div>
</div>
</div>
</li>
{/each}
</li>
{/each}{/if}
</ul>
</div>
</dialog>
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
<script lang="ts">
import { onDestroy, onMount } from 'svelte';

// This component will help us to programmatically do the same as
// CSS media queries. We can use it to show/hide elements or render
// different components based on whether or not the size is desktop
// or larger
const isLgMediaQuery = window.matchMedia('(min-width: 1024px)');
const isMdMediaQuery = window.matchMedia('(min-width: 768px)');
import { browser } from '$app/environment';

export let windowSize: 'sm' | 'md' | 'lg' = 'md';

Expand All @@ -18,15 +13,24 @@
windowSize = event.matches ? 'md' : 'sm';
}

onMount(() => {
isLgMediaQuery.addEventListener('change', isLgQueryHandler);
isMdMediaQuery.addEventListener('change', isMdQueryHandler);
//assign starting value
windowSize = window.innerWidth > 1024 ? 'lg' : window.innerWidth < 768 ? 'sm' : 'md';
});
if (browser) {
// This component will help us to programmatically do the same as
// CSS media queries. We can use it to show/hide elements or render
// different components based on whether or not the size is desktop
// or larger
const isLgMediaQuery = window.matchMedia('(min-width: 1024px)');
const isMdMediaQuery = window.matchMedia('(min-width: 768px)');

onDestroy(() => {
isLgMediaQuery.removeEventListener('change', isLgQueryHandler);
isMdMediaQuery.removeEventListener('change', isMdQueryHandler);
});
onMount(() => {
isLgMediaQuery.addEventListener('change', isLgQueryHandler);
isMdMediaQuery.addEventListener('change', isMdQueryHandler);
//assign starting value
windowSize = window.innerWidth > 1024 ? 'lg' : window.innerWidth < 768 ? 'sm' : 'md';
});

onDestroy(() => {
isLgMediaQuery.removeEventListener('change', isLgQueryHandler);
isMdMediaQuery.removeEventListener('change', isMdQueryHandler);
});
}
</script>
2 changes: 1 addition & 1 deletion packages/taikoon-ui/src/generated/abi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ export const taikoonTokenAbi = [
*/
export const taikoonTokenAddress = {
17000: '0xfDbaA6d6c382A2555856bFaB315D5E6F3CDA1393',
31337: '0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512',
31337: '0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0',
167001: '0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512',
} as const;

Expand Down
22 changes: 11 additions & 11 deletions packages/taikoon-ui/src/lib/chain/chains.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Chain } from 'viem';

import { type ChainConfig, type ChainConfigMap, LayerType } from '../../lib/chain';
import { type ChainConfig, type ChainConfigMap, LayerType } from '.';

//import { chainConfig } from '$chainConfig';

Expand Down Expand Up @@ -107,33 +107,33 @@ export const chains: Chain[] = Object.entries(chainConfigs).map(([chainId, chain
mapChainConfigToChain(chainId, chainConfig as ChainConfig),
);

export const getConfiguredChainIds = (): number[] => {
export function getConfiguredChainIds(): number[] {
return chains.map((chain) => Number(chain.id));
};
}

export const isSupportedChain = (chainId: number) => {
export function isSupportedChain(chainId: number) {
return chains.some((chain) => chain.id === chainId);
};
}

export const getChainImages = (): Record<number, string> => {
export function getChainImages(): Record<number, string> {
return Object.fromEntries(
Object.entries(chainConfigs).map(([chainId]) => [Number(chainId), chainConfigs[Number(chainId)].icon]),
);
};
}

export const getChainImage = (chainId: number) => {
export function getChainImage(chainId: number) {
const images = getChainImages();
if (!images[chainId]) {
throw new Error(`Chain with id ${chainId} not found`);
}

return images[chainId];
};
}

export const getChainName = (chainId: number) => {
export function getChainName(chainId: number) {
const chain = chains.find((chain) => chain.id === chainId);
if (!chain) {
throw new Error(`Chain with id ${chainId} not found`);
}
return chain.name;
};
}
5 changes: 3 additions & 2 deletions packages/taikoon-ui/src/lib/connect/web3modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { getAccount, getChainId, watchAccount, watchChainId } from '@wagmi/core'
import { createWeb3Modal } from '@web3modal/wagmi';
import { readable } from 'svelte/store';

import { browser } from '$app/environment';
import { PUBLIC_WALLETCONNECT_PROJECT_ID } from '$env/static/public';
import { config } from '$wagmi-config';

import { getChainImages } from '../../lib/chain';
import { getChainImages } from '../../lib/chain/chains';

const projectId = PUBLIC_WALLETCONNECT_PROJECT_ID || 'walletconnect-project-id';
const chainImages = getChainImages();
Expand Down Expand Up @@ -37,5 +38,5 @@ export const web3modal = createWeb3Modal({
'--w3m-border-radius-master': '9999px',
'--w3m-accent': 'var(--primary-brand)',
},
themeMode: (localStorage.getItem('theme') as 'dark' | 'light') ?? 'dark',
themeMode: browser ? (localStorage.getItem('theme') as 'dark' | 'light') ?? 'dark' : 'dark',
});
2 changes: 1 addition & 1 deletion packages/taikoon-ui/src/lib/wagmi/watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ export async function startWatching() {
}

export function stopWatching() {
unWatchAccount();
unWatchAccount && unWatchAccount();
isWatching = false;
}
7 changes: 7 additions & 0 deletions packages/taikoon-ui/src/routes/+error.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script>
import { page } from '$app/stores';
</script>

{#if $page && $page.error && $page.error.message}
<h1>{$page.error.message}</h1>
{/if}
2 changes: 1 addition & 1 deletion packages/taikoon-ui/src/routes/+layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
// which essentially means you turn your app into an SPA.
// See https://kit.svelte.dev/docs/page-options#ssr

export const ssr = false;
export const ssr = true;
37 changes: 37 additions & 0 deletions packages/taikoon-ui/src/routes/+page.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { error } from '@sveltejs/kit';

const blacklistedCountries = [
'AF', // Afghanistan (AF)
'BY', // Belarus (BY)
'MM', // Burma/Myanmar (MM)
'CF', // Central African Republic (CF)
'CN', // China (CN)
'CU', // Cuba (CU)
'CD', // Democratic Republic of the Congo (CD)
'ET', // Ethiopia (ET)
'IR', // Iran (IR)
'IQ', // Iraq (IQ)
'LB', // Lebanon (LB)
'LY', // Libya (LY)
'ML', // Mali (ML)
'NI', // Nicaragua (NI)
'KP', // North Korea (KP)
'RU', // Russia (RU)
'SO', // Somalia (SO)
'SS', // South Sudan (SS)
'SD', // Sudan (SD)
'SY', // Syria (SY)
'VE', // Venezuela (VE)
'US', // United States (US)
];

export function load(event: any) {
const country = event.request.headers.get('x-vercel-ip-country') ?? false;
const isDev = event.url.hostname === 'localhost';
if (!isDev && (!country || blacklistedCountries.includes(country))) {
return error(400, { message: 'This site is not available in your country.' });
}
return {
location: { country },
};
}
4 changes: 4 additions & 0 deletions packages/taikoon-ui/src/routes/blocked/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<script lang="ts">
</script>

<h1>Seems that you have been blocked</h1>
bearni95 marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion packages/taikoon-ui/svelte.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import adapter from '@sveltejs/adapter-auto'
bearni95 marked this conversation as resolved.
Show resolved Hide resolved
import adapter from '@sveltejs/adapter-auto';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'
/** @type {import('@sveltejs/kit').Config} */
const config = {
Expand Down
2 changes: 1 addition & 1 deletion packages/taikoon-ui/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
//"$relayerConfig": ["./src/generated/relayerConfig.ts"],
//"$customToken": ["./src/generated/customTokenConfig.ts"]
},
"rootDirs": [".", "./.svelte-kit/types", "./$houdini/types"]
"rootDirs": [".", "./.svelte-kit/types"]
}
// Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias
// except $lib which is handled by https://kit.svelte.dev/docs/configuration#files
Expand Down
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.