From 12c153aef13d8610c56413efea74179cbb807607 Mon Sep 17 00:00:00 2001 From: Christophe de Carvalho Date: Wed, 15 Nov 2023 20:31:36 +0000 Subject: [PATCH 01/12] refactor: new main UI - use all the screen available space - more information about contributors + bigger avatar - possiblity to choose the amount of reward to send per contributor - better mobil size support --- src/lib/components/Balance.svelte | 6 ++- src/lib/components/ContributorCard.svelte | 43 ++++++++++++++++ src/lib/components/Web3Modal.svelte | 2 +- src/lib/pages/dasboard/lib.ts | 48 ++++++++++++++++++ src/lib/{ => services}/github.ts | 2 +- src/lib/{ => services}/mail.ts | 2 +- src/lib/{ => services}/networks.ts | 0 src/lib/{ => services}/peanutes.ts | 0 src/lib/{ => services}/socketTech.ts | 0 src/lib/{ => services}/wallet.ts | 0 src/lib/types.ts | 11 ++++ src/routes/+layout.svelte | 7 +-- src/routes/+page.svelte | 7 +-- src/routes/api/github/+server.ts | 3 +- src/routes/api/mail/+server.ts | 2 +- src/routes/dashboard/+page.svelte | 62 +++++++++++++++++++++++ 16 files changed, 182 insertions(+), 13 deletions(-) create mode 100644 src/lib/components/ContributorCard.svelte create mode 100644 src/lib/pages/dasboard/lib.ts rename src/lib/{ => services}/github.ts (89%) rename src/lib/{ => services}/mail.ts (96%) rename src/lib/{ => services}/networks.ts (100%) rename src/lib/{ => services}/peanutes.ts (100%) rename src/lib/{ => services}/socketTech.ts (100%) rename src/lib/{ => services}/wallet.ts (100%) create mode 100644 src/routes/dashboard/+page.svelte diff --git a/src/lib/components/Balance.svelte b/src/lib/components/Balance.svelte index b836b7d..58823d5 100644 --- a/src/lib/components/Balance.svelte +++ b/src/lib/components/Balance.svelte @@ -1,12 +1,14 @@ + +
(selected = !selected)} + on:keypress={onKeyPress} + {tabindex} + role="button" +> +
+
+
+ avatar +
+
+ Name: {contributor?.name} + Email: {contributor?.email} + +
+
+
+
+

+ {contributor.numberOfContributions} + Contribution{#if contributor.numberOfContributions > 1}s{/if} + over last 30 days +

+
+
diff --git a/src/lib/components/Web3Modal.svelte b/src/lib/components/Web3Modal.svelte index 8591844..4f76fd6 100644 --- a/src/lib/components/Web3Modal.svelte +++ b/src/lib/components/Web3Modal.svelte @@ -1,8 +1,8 @@ + +
+
+

Search

+ +
+
+
https://github.com/
+ +
+
+
+ + Multi rewards + {#if selected.length > 0} + + {/if} +
+
+
+

Contributors

+
+ {#each contributors as contributor} + + {/each} +
+
+
From 19bc343fea6f25f893b7318ccb49656490f9e64d Mon Sep 17 00:00:00 2001 From: Christophe de Carvalho Date: Fri, 17 Nov 2023 19:35:53 +0000 Subject: [PATCH 02/12] wip dashboard form --- src/lib/components/Balance.svelte | 9 ++++- src/lib/components/ContributorCard.svelte | 48 ++++++++++++++++++----- src/lib/services/wallet.ts | 2 +- src/routes/+layout.svelte | 11 +++++- src/routes/+page.svelte | 1 - src/routes/dashboard/+page.svelte | 23 ++++++++++- 6 files changed, 78 insertions(+), 16 deletions(-) diff --git a/src/lib/components/Balance.svelte b/src/lib/components/Balance.svelte index 58823d5..418b292 100644 --- a/src/lib/components/Balance.svelte +++ b/src/lib/components/Balance.svelte @@ -4,6 +4,7 @@ import { balances } from '$lib/services/socketTech'; export let token: BalanceResult; + export let alternative: boolean = false; let selected: BalanceResult; $: sortedBalance = $balances.sort((a: BalanceResult, b: BalanceResult) => @@ -16,7 +17,13 @@ } - (token = selected)} +> {#each sortedBalance as balance} {/each} diff --git a/src/lib/components/ContributorCard.svelte b/src/lib/components/ContributorCard.svelte index 299ce0f..2061c5c 100644 --- a/src/lib/components/ContributorCard.svelte +++ b/src/lib/components/ContributorCard.svelte @@ -1,23 +1,36 @@
(selected = !selected)} - on:keypress={onKeyPress} - {tabindex} - role="button" > +
+ +

@{contributor?.login}

+
+
-
+
(selected = !selected)} + on:keypress={onKeyPress} + {tabindex} + >
avatar
-
- Name: {contributor?.name} - Email: {contributor?.email} +
+

Name: {contributor?.name}

+

Email: {contributor?.email}

+ {#if reward} +
+ + +
+ {/if}

diff --git a/src/lib/services/wallet.ts b/src/lib/services/wallet.ts index 8e482f4..6b7bedd 100644 --- a/src/lib/services/wallet.ts +++ b/src/lib/services/wallet.ts @@ -5,7 +5,7 @@ import type { Web3Modal } from '@web3modal/ethers5/dist/types/src/client'; import type { ethers } from 'ethers'; import { writable } from 'svelte/store'; -import type { PeanutChain } from './types'; +import type { PeanutChain } from '../types'; export interface OpenOptions { view: 'Account' | 'Connect' | 'Networks'; diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 7ce129b..d76f799 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -2,8 +2,15 @@ import '../app.postcss'; import { arrow, autoUpdate, computePosition, flip, offset, shift } from '@floating-ui/dom'; - import { AppBar, AppShell, initializeStores, LightSwitch,storePopup, Toast } from '@skeletonlabs/skeleton'; - import { inject } from '@vercel/analytics'; + import { + AppBar, + AppShell, + initializeStores, + LightSwitch, + storePopup, + Toast + } from '@skeletonlabs/skeleton'; + import { inject } from '@vercel/analytics'; import { dev } from '$app/environment'; import Web3Modal from '$lib/components/Web3Modal.svelte'; diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 7ca14e6..3b5201a 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -122,7 +122,6 @@ } toastStore.close(toastId); } catch (error) { - console.log(error); toastStore.trigger({ message: 'failed to generate rewards', background: 'variant-filled-warning' diff --git a/src/routes/dashboard/+page.svelte b/src/routes/dashboard/+page.svelte index 1b51d76..83d8156 100644 --- a/src/routes/dashboard/+page.svelte +++ b/src/routes/dashboard/+page.svelte @@ -6,6 +6,19 @@ import { loadContributors } from '$lib/pages/dasboard/lib'; import type { Contributor } from '$lib/types'; + import type { Snapshot } from './$types'; + + export const snapshot: Snapshot = { + capture: () => JSON.stringify({ repository, contributors, selectAll, multiReward }), + restore: (value) => { + let data = JSON.parse(value); + repository = data.repository; + contributors = data.contributors; + selectAll = data.selectAll; + multiReward = data.multiReward; + } + }; + const { debounce } = pkg; let repository: string = ''; @@ -44,7 +57,13 @@

- + Multi rewards {#if selected.length > 0} @@ -55,7 +74,7 @@

Contributors

{#each contributors as contributor} - + {/each}
From b4b769d32f972fa98c7d5db3c2163e26fdd59807 Mon Sep 17 00:00:00 2001 From: Christophe de Carvalho Date: Fri, 24 Nov 2023 12:17:28 +0000 Subject: [PATCH 03/12] wip again --- src/lib/components/ContributorCard.svelte | 6 +- src/lib/services/{peanutes.ts => peanut.ts} | 28 +++--- src/lib/services/reward.ts | 51 +++++++++++ src/routes/+page.svelte | 17 ++-- src/routes/dashboard/+page.svelte | 99 +++++++++++++++++---- 5 files changed, 160 insertions(+), 41 deletions(-) rename src/lib/services/{peanutes.ts => peanut.ts} (51%) create mode 100644 src/lib/services/reward.ts diff --git a/src/lib/components/ContributorCard.svelte b/src/lib/components/ContributorCard.svelte index 2061c5c..3476f38 100644 --- a/src/lib/components/ContributorCard.svelte +++ b/src/lib/components/ContributorCard.svelte @@ -4,13 +4,17 @@ import type { Contributor } from '$lib/types'; import Balance from './Balance.svelte'; + import { createEventDispatcher } from 'svelte'; + const dispatch = createEventDispatcher(); export let contributor: Contributor; export let selected: boolean = false; export let tabindex = 0; export let reward: boolean = false; let selectedToken: BalanceResult; - function onKeyPress() {} + function onKeyPress() { + dispatch('selected', selected); + }
{ + await sendEmail({ + name: params.selected[i].name, + email: params.selected[i].email, + repoName: params.repository, + message: 'Thanks for your contribution!', + link: link.link + }); + }) + ); +} + +async function sendEmail(email: Email) { + console.log('send email:', { ...email }); + return fetch(`/api/mail`, { + method: 'POST', + body: JSON.stringify(email) + }); +} diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 3b5201a..fb89af1 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -1,5 +1,6 @@
-
-

Search

- +
https://github.com/
@@ -56,26 +83,60 @@ />
-
- - Multi rewards + + Multi rewards +
{#if selected.length > 0} - + {#if !multiReward} +
+ + +
+ {/if} + {/if}
-

Contributors

-
- {#each contributors as contributor} - - {/each} -
+ {#if !repository} +
+
No repository selected
+
Specify the name of a repository to start
+
+ {:else if repository && contributors.length === 0} +
+
No contributors found
+
Try another repository
+
+ {:else} +
+ {#each contributors as contributor} + + {/each} +
+ {/if}
From 624ce291f03cee3b45b99d9e7cd88a35c72e0d0c Mon Sep 17 00:00:00 2001 From: Christophe de Carvalho Date: Wed, 17 Jan 2024 22:51:59 +0000 Subject: [PATCH 04/12] wip to review --- src/lib/components/Balance.svelte | 4 +- src/lib/components/ContributorCard.svelte | 6 +- src/lib/pages/{dasboard => dashboard}/lib.ts | 0 src/lib/services/reward.ts | 3 +- src/routes/+page.svelte | 8 +- src/routes/dashboard/+page.svelte | 78 +++++++++++++++++--- 6 files changed, 78 insertions(+), 21 deletions(-) rename src/lib/pages/{dasboard => dashboard}/lib.ts (100%) diff --git a/src/lib/components/Balance.svelte b/src/lib/components/Balance.svelte index 418b292..d64aff5 100644 --- a/src/lib/components/Balance.svelte +++ b/src/lib/components/Balance.svelte @@ -19,8 +19,8 @@ (token = selected)} -> - {#each sortedBalance as balance} - - {/each} - +
+ + + +
diff --git a/src/lib/components/ContributorCard.svelte b/src/lib/components/ContributorCard.svelte index ffa44a8..d8a9bf6 100644 --- a/src/lib/components/ContributorCard.svelte +++ b/src/lib/components/ContributorCard.svelte @@ -12,6 +12,7 @@ export let tabindex = 0; export let reward: boolean = false; let selectedToken: BalanceResult; + let rewardAmount: number; function onKeyPress() { dispatch('selected', selected); } @@ -59,11 +60,7 @@ inputmode="numeric" placeholder="Amount" /> - +
{/if} diff --git a/src/lib/services/wallet.ts b/src/lib/services/wallet.ts index 6b7bedd..ec8f29f 100644 --- a/src/lib/services/wallet.ts +++ b/src/lib/services/wallet.ts @@ -1,12 +1,12 @@ // import { chains } from '$lib/consts/chains'; import { CHAIN_DETAILS } from '@squirrel-labs/peanut-sdk'; import { createWeb3Modal, defaultConfig } from '@web3modal/ethers5'; -import type { Web3Modal } from '@web3modal/ethers5/dist/types/src/client'; -import type { ethers } from 'ethers'; +import { ethers } from 'ethers'; import { writable } from 'svelte/store'; import type { PeanutChain } from '../types'; +type Web3Modal = ReturnType; export interface OpenOptions { view: 'Account' | 'Connect' | 'Networks'; } @@ -16,10 +16,6 @@ let modal: Web3Modal | null = null; export const getAccountStores = () => accountStores; export const accountStores = { - provider: writable(undefined), - providerType: writable<'walletConnect' | 'injected' | 'coinbaseWallet' | 'eip6963' | undefined>( - undefined - ), address: writable(undefined), chainId: writable(undefined), isConnected: writable(false), @@ -55,16 +51,14 @@ export function initWeb3Modal() { projectId }); - //TODO: unsubribe + //TODO: unsubscribe modal?.subscribeProvider((newState) => { - accountStores.provider.set(newState.provider); - accountStores.providerType.set(newState.providerType); accountStores.address.set(newState.address); accountStores.chainId.set(newState.chainId); accountStores.isConnected.set(newState.isConnected); }); - //TODO: unsubribe + //TODO: unsubscribe modal?.subscribeState((newState) => { modalSateStores.selectedNetworkId.set(newState.selectedNetworkId); modalSateStores.isOpen.set(newState.open); @@ -72,9 +66,13 @@ export function initWeb3Modal() { } function getSigner(): ethers.providers.JsonRpcSigner | undefined { - if (modal) { - return modal.getSigner(); - } + if (!modal) return undefined; + const provider = modal.getWalletProvider(); + + if (!provider) return undefined; + + const p = new ethers.providers.Web3Provider(provider); + return p.getSigner(); } export async function open(options?: OpenOptions) { diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 6e5d700..c4c3e78 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -10,17 +10,29 @@ import { getAccountStores, open } from '$lib/services/wallet'; import type { Author, CommitDetail, Email, User } from '$lib/types'; + import type { Snapshot } from './$types'; + + export const snapshot: Snapshot = { + capture: () => JSON.stringify({ repository, contributorsNr, rewardAmount }), + restore: (value) => { + let data = JSON.parse(value); + repository = data.repository; + contributorsNr = data.contributorsNr; + rewardAmount = data.rewardAmount; + } + }; + const { isConnected, chainId, getSigner } = getAccountStores(); const toastStore = getToastStore(); // export let data: PageData; let repository: string | null = $page.url.searchParams.get('repository'); - let contributorsNr: number | null = $page.url.searchParams.has('contributor') + let contributorsNr: number = $page.url.searchParams.has('contributor') ? parseInt($page.url.searchParams.get('contributor') ?? '0') - : null; - let rewardAmount: number | null = $page.url.searchParams.has('reward') + : 0; + let rewardAmount: number = $page.url.searchParams.has('reward') ? parseFloat($page.url.searchParams.get('reward') ?? '0') - : null; + : 0; let creatingLinks = false; let top: string[] = []; @@ -187,15 +199,7 @@ /> {#if top.length > 0}
- - +
Top contributors diff --git a/src/routes/dashboard/+page.svelte b/src/routes/dashboard/+page.svelte index d58c611..81d23b5 100644 --- a/src/routes/dashboard/+page.svelte +++ b/src/routes/dashboard/+page.svelte @@ -25,59 +25,61 @@ const { getSigner, chainId } = getAccountStores(); - let repository: string = 'zaibon/commitkudos'; - let contributors: Contributor[] = [ - { - login: 'zaibon', - name: 'christophe de Carvalho', - avatarUrl: '/android-chrome-192x192.png', - email: 'user@mail.com', - twitter: '', - discord: '', - checked: false, - numberOfContributions: 10 - }, - { - login: 'zaibon', - name: 'christophe de Carvalho', - avatarUrl: '/android-chrome-192x192.png', - email: 'user@mail.com', - twitter: '', - discord: '', - checked: false, - numberOfContributions: 10 - }, - { - login: 'zaibon', - name: 'christophe de Carvalho', - avatarUrl: '/android-chrome-192x192.png', - email: 'user@mail.com', - twitter: '', - discord: '', - checked: false, - numberOfContributions: 10 - }, - { - login: 'zaibon', - name: 'christophe de Carvalho', - avatarUrl: '/android-chrome-192x192.png', - email: 'user@mail.com', - twitter: '', - discord: '', - checked: false, - numberOfContributions: 10 - }, - { - login: 'zaibon', - name: 'christophe de Carvalho', - avatarUrl: '/android-chrome-192x192.png', - email: 'user@mail.com', - twitter: '', - discord: '', - checked: false, - numberOfContributions: 10 - } - ]; + // let repository: string = 'zaibon/py-dmidecode'; + let repository: string = ''; + let contributors: Contributor[] = []; + // let contributors: Contributor[] = [ + // { + // login: 'zaibon', + // name: 'christophe de Carvalho', + // avatarUrl: '/android-chrome-192x192.png', + // email: 'user@mail.com', + // twitter: '', + // discord: '', + // checked: false, + // numberOfContributions: 10 + // }, + // { + // login: 'zaibon', + // name: 'christophe de Carvalho', + // avatarUrl: '/android-chrome-192x192.png', + // email: 'user@mail.com', + // twitter: '', + // discord: '', + // checked: false, + // numberOfContributions: 10 + // }, + // { + // login: 'zaibon', + // name: 'christophe de Carvalho', + // avatarUrl: '/android-chrome-192x192.png', + // email: 'user@mail.com', + // twitter: '', + // discord: '', + // checked: false, + // numberOfContributions: 10 + // }, + // { + // login: 'zaibon', + // name: 'christophe de Carvalho', + // avatarUrl: '/android-chrome-192x192.png', + // email: 'user@mail.com', + // twitter: '', + // discord: '', + // checked: false, + // numberOfContributions: 10 + // }, + // { + // login: 'zaibon', + // name: 'christophe de Carvalho', + // avatarUrl: '/android-chrome-192x192.png', + // email: 'user@mail.com', + // twitter: '', + // discord: '', + // checked: false, + // numberOfContributions: 10 + // } + // ]; let selectAll: boolean = false; let multiReward: boolean = false; let selectedToken: BalanceResult; @@ -152,14 +154,7 @@ {#if selected.length > 0} {#if !multiReward}
- - +
{/if} - + - +
{/if} diff --git a/src/lib/pages/dashboard/lib.ts b/src/lib/pages/dashboard/lib.ts index e3ae3a1..904f069 100644 --- a/src/lib/pages/dashboard/lib.ts +++ b/src/lib/pages/dashboard/lib.ts @@ -19,6 +19,9 @@ export async function loadContributors(repository: string): Promise { await sendEmail({ - name: params.selected[i].name, - email: params.selected[i].email, + name: params.contributors[i].name, + email: params.contributors[i].email, repoName: params.repository, message: 'Thanks for your contribution!', link: link.link }); }) ); + return links; } async function sendEmail(email: Email) { diff --git a/src/lib/types.ts b/src/lib/types.ts index fcaeaa1..4f9b936 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -1,3 +1,5 @@ +import type { BalanceResult } from '@socket.tech/socket-v2-sdk'; + export interface CommitDetail { sha: string; node_id: string; @@ -147,3 +149,8 @@ export interface Badge { cacheSeconds?: number; link?: string; } +export interface RewardAmount { + contributor: Contributor; + amount: number; + token: BalanceResult; +} diff --git a/src/routes/dashboard/+page.svelte b/src/routes/dashboard/+page.svelte index 81d23b5..27738f2 100644 --- a/src/routes/dashboard/+page.svelte +++ b/src/routes/dashboard/+page.svelte @@ -1,6 +1,6 @@ - {network?.name ?? ''} + {#if $chainInfo} + {$chainInfo?.name ?? ''} + {/if}