forked from aboutcircles/circles-code-quest
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'refs/heads/feature/support-v2'
- Loading branch information
Showing
24 changed files
with
415 additions
and
3,336 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,30 +1,30 @@ | ||
{ | ||
"name": "circles-app", | ||
"version": "0.0.1", | ||
"private": true, | ||
"scripts": { | ||
"dev": "vite dev", | ||
"build": "vite build", | ||
"preview": "vite preview", | ||
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", | ||
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch" | ||
}, | ||
"devDependencies": { | ||
"@sveltejs/adapter-auto": "^3.0.0", | ||
"@sveltejs/kit": "^2.0.0", | ||
"@sveltejs/vite-plugin-svelte": "^3.0.0", | ||
"autoprefixer": "^10.4.19", | ||
"postcss": "^8.4.38", | ||
"svelte": "^4.2.7", | ||
"svelte-check": "^3.6.0", | ||
"tailwindcss": "^3.4.3", | ||
"tslib": "^2.4.1", | ||
"typescript": "^5.0.0", | ||
"vite": "^5.0.3", | ||
"ethers": "^6.12.1", | ||
"@circles-sdk/data": "0.0.41", | ||
"@circles-sdk/sdk": "0.0.41", | ||
"@circles-sdk/utils": "0.0.41" | ||
}, | ||
"type": "module" | ||
"name": "circles-app", | ||
"version": "0.0.1", | ||
"private": true, | ||
"scripts": { | ||
"dev": "vite dev", | ||
"build": "vite build", | ||
"preview": "vite preview", | ||
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", | ||
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch" | ||
}, | ||
"devDependencies": { | ||
"@sveltejs/adapter-auto": "^3.0.0", | ||
"@sveltejs/kit": "^2.0.0", | ||
"@sveltejs/vite-plugin-svelte": "^3.0.0", | ||
"autoprefixer": "^10.4.19", | ||
"postcss": "^8.4.38", | ||
"svelte": "^4.2.7", | ||
"svelte-check": "^3.6.0", | ||
"tailwindcss": "^3.4.3", | ||
"tslib": "^2.4.1", | ||
"typescript": "^5.0.0", | ||
"vite": "^5.0.3", | ||
"ethers": "^6.12.1", | ||
"@circles-sdk/data": "0.0.45-preview-29", | ||
"@circles-sdk/sdk": "0.0.45-preview-29", | ||
"@circles-sdk/utils": "0.0.45-preview-29" | ||
}, | ||
"type": "module" | ||
} |
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,11 @@ | ||
import {avatar} from "$lib/stores/avatar"; | ||
import {get} from "svelte/store"; | ||
import {ContractTransactionReceipt} from "ethers"; | ||
|
||
export async function inviteHuman(contactAddress: string): Promise<ContractTransactionReceipt> { | ||
const avatarValue = get(avatar); | ||
if (!avatarValue) { | ||
throw new Error('Avatar is not initialized'); | ||
} | ||
return await avatarValue.inviteHuman(contactAddress); | ||
} |
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,18 +1,56 @@ | ||
<script lang="ts"> | ||
import {avatar} from "$lib/stores/avatar"; | ||
import {onDestroy, onMount} from "svelte"; | ||
$: address = $avatar?.address; | ||
$: balance = $avatar?.getTotalBalance(); | ||
$: mintableAmount = $avatar?.getMintableAmount(); | ||
let timeout: NodeJS.Timeout | undefined; | ||
let unsubscribe: (() => void) | undefined; | ||
$:console.log("AccountInfoHeader.svelte: $avatar", $avatar?.avatarInfo); | ||
onMount(() => { | ||
timeout = setTimeout(() => { | ||
mintableAmount = $avatar?.getMintableAmount(); | ||
}, 60000); | ||
unsubscribe = $avatar?.events.subscribe(async event => { | ||
if (event.$event !== "CrcV2_TransferBatch" | ||
&& event.$event !== "CrcV2_TransferSingle" | ||
&& event.$event !== "CrcV1_Transfer" | ||
&& event.$event !== "CrcV1_HubTransfer") { | ||
return; | ||
} | ||
balance = $avatar?.getTotalBalance(); | ||
mintableAmount = $avatar?.getMintableAmount(); | ||
}); | ||
}); | ||
onDestroy(() => { | ||
clearTimeout(timeout); | ||
unsubscribe?.(); | ||
}); | ||
</script> | ||
|
||
<header class="bg-blue-500 text-white p-4 flex items-center"> | ||
<img src="/logo.svg" alt="User Icon" class="w-12 h-12 rounded-full"> | ||
<div class="ml-4"> | ||
<h1 class="text-xl font-semibold">{address}</h1> | ||
{#await balance} | ||
<p class="text-sm">0 Circles</p> | ||
{:then balance} | ||
<p class="text-sm">{balance?.toFixed(2) ?? 0} Circles</p> | ||
{/await} | ||
<p class="text-sm"> | ||
{#await balance} | ||
----.-- Circles | ||
{:then balance} | ||
{balance?.toFixed(2) ?? 0} Circles | ||
{:catch error} | ||
(Error loading balance) | ||
{/await} | ||
|
||
{#await mintableAmount} | ||
{:then mintableAmount} | ||
<span class="text-amber-200">({mintableAmount} Circles available to mint)</span> | ||
{/await} | ||
</p> | ||
</div> | ||
</header> |
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
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,17 @@ | ||
<script lang="ts"> | ||
import {goto} from "$app/navigation"; | ||
async function migrateToV2() { | ||
await goto("/migrate-to-v2"); | ||
} | ||
</script> | ||
<div class="bg-blue-100 border-t-4 mb-4 border-blue-500 rounded-b text-blue-900 px-4 py-3 shadow-md cursor-pointer" | ||
on:click={() => migrateToV2()} | ||
role="alert"> | ||
<div class="flex"> | ||
<div> | ||
<p class="font-bold">Circles V2 is here!</p> | ||
<p class="text-sm">Migrate your avatar to Circles V2.</p> | ||
</div> | ||
</div> | ||
</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,15 @@ | ||
import type {AvatarRow} from "@circles-sdk/data"; | ||
|
||
export function canInvite(avatar: AvatarRow | undefined): boolean { | ||
// Invitations only work for human v2 avatars. | ||
// If they have a v1 token, it must be stopped. | ||
if (!avatar) { | ||
return false; | ||
} | ||
|
||
return avatar.version === 2 | ||
&& avatar.type === "human" | ||
&& (avatar.hasV1 | ||
? avatar.v1Stopped === true | ||
: true); | ||
} |
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,19 @@ | ||
import type {AvatarRow} from "@circles-sdk/data"; | ||
|
||
export function canMigrate(avatar: AvatarRow | undefined): boolean { | ||
if (!avatar) { | ||
return false; | ||
} | ||
|
||
// Pure v1 avatars can migrate | ||
if (avatar.version === 1) { | ||
return true; | ||
} | ||
|
||
// v2 avatars can migrate if they have a v1 token and it's not stopped | ||
if (avatar.hasV1 && avatar.version === 2) { | ||
return !avatar.v1Stopped ?? false; | ||
} | ||
|
||
return false; | ||
} |
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,7 +1,7 @@ | ||
import {writable} from "svelte/store"; | ||
import type {AvatarInterface} from "@circles-sdk/sdk"; | ||
import {Avatar} from "@circles-sdk/sdk"; | ||
|
||
/** | ||
* A store that contains an Avatar instance or undefined. | ||
*/ | ||
export const avatar = writable<AvatarInterface | undefined>(); | ||
export const avatar = writable<Avatar | undefined>(); |
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,12 @@ | ||
import {redirect} from "@sveltejs/kit"; | ||
import {wallet} from "$lib/stores/wallet"; | ||
import {get} from "svelte/store"; | ||
|
||
export const load = (params): void => { | ||
// Redirect to 'connect wallet' if not connected | ||
if (params.route.id !== '/connect-wallet' | ||
&& params.route.id !== '/' | ||
&& get(wallet) === undefined) { | ||
redirect(302, '/connect-wallet'); | ||
} | ||
}; |
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
Oops, something went wrong.