From 44621cb51b916b32921675e612136b46febc9b87 Mon Sep 17 00:00:00 2001 From: Igor Shadurin Date: Sat, 10 Jun 2023 11:29:38 +0300 Subject: [PATCH] refactor: info modal for copied alert --- .example.env.local | 3 +++ .github/workflows/buildx.yml | 3 +++ .github/workflows/docker.yml | 1 + .github/workflows/swarm.yml | 3 +++ src/components/Invite/Invite.tsx | 6 ++++++ src/utils/invite.ts | 36 ++++++++++++++++++++++++++++++++ 6 files changed, 52 insertions(+) diff --git a/.example.env.local b/.example.env.local index c1805727..27c1e024 100644 --- a/.example.env.local +++ b/.example.env.local @@ -22,3 +22,6 @@ NEXT_PUBLIC_BB_RULES_URL=https://create.fairdatasociety.org/#/bb-rules # Create account url for Big Bang campaign NEXT_PUBLIC_BB_CREATE_ACCOUNT_URL=https://create.fairdatasociety.org + +# Big Bang API url +NEXT_PUBLIC_BB_API_URL=https://bbapi.fairdatasociety.org diff --git a/.github/workflows/buildx.yml b/.github/workflows/buildx.yml index 37abb077..c523171f 100644 --- a/.github/workflows/buildx.yml +++ b/.github/workflows/buildx.yml @@ -49,6 +49,7 @@ jobs: echo "NEXT_PUBLIC_ENVIRONMENT=SEPOLIA" >> "$GITHUB_ENV" echo "NEXT_PUBLIC_BB_RULES_URL=https://create.fairdatasociety.org/#/bb-rules" >> "$GITHUB_ENV" echo "NEXT_PUBLIC_BB_CREATE_ACCOUNT_URL=https://create.fairdatasociety.org" >> "$GITHUB_ENV" + echo "NEXT_PUBLIC_BB_API_URL=https://bbapi.fairdatasociety.org" >> "$GITHUB_ENV" elif [ "$GITHUB_REF_NAME" == 'development' ]; then echo "NEXT_PUBLIC_FAIROSHOST=https://app.fairos.dev.fairdatasociety.org" >> "$GITHUB_ENV" echo "NEXT_PUBLIC_FAIRDRIVEHOST=https://app.fairdrive.dev.fairdatasociety.org" >> "$GITHUB_ENV" @@ -61,6 +62,7 @@ jobs: echo "NEXT_PUBLIC_ENVIRONMENT=SEPOLIA" >> "$GITHUB_ENV" echo "NEXT_PUBLIC_BB_RULES_URL=https://create.dev.fairdatasociety.org/#/bb-rules" >> "$GITHUB_ENV" echo "NEXT_PUBLIC_BB_CREATE_ACCOUNT_URL=https://create.dev.fairdatasociety.org" >> "$GITHUB_ENV" + echo "NEXT_PUBLIC_BB_API_URL=https://bbapi.fairdatasociety.org" >> "$GITHUB_ENV" elif [ "$GITHUB_REF_NAME" == 'staging' ]; then echo "NEXT_PUBLIC_FAIROSHOST=https://fairos.staging.fairdatasociety.org" >> "$GITHUB_ENV" echo "NEXT_PUBLIC_FAIRDRIVEHOST=https://fairdrive.staging.fairdatasociety.org" >> "$GITHUB_ENV" @@ -73,6 +75,7 @@ jobs: echo "NEXT_PUBLIC_ENVIRONMENT=SEPOLIA" >> "$GITHUB_ENV" echo "NEXT_PUBLIC_BB_RULES_URL=https://create.staging.fairdatasociety.org/#/bb-rules" >> "$GITHUB_ENV" echo "NEXT_PUBLIC_BB_CREATE_ACCOUNT_URL=https://create.staging.fairdatasociety.org" >> "$GITHUB_ENV" + echo "NEXT_PUBLIC_BB_API_URL=https://bbapi.fairdatasociety.org" >> "$GITHUB_ENV" fi - name: copy ca diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index d4ceff69..4378ae22 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -41,3 +41,4 @@ jobs: "NEXT_PUBLIC_CREATE_ACCOUNT_REDIRECT=http://localhost" "NEXT_PUBLIC_BB_RULES_URL=https://create.dev.fairdatasociety.org/#/bb-rules" "NEXT_PUBLIC_BB_CREATE_ACCOUNT_URL=https://create.staging.fairdatasociety.org" + "NEXT_PUBLIC_BB_API_URL=https://bbapi.fairdatasociety.org" diff --git a/.github/workflows/swarm.yml b/.github/workflows/swarm.yml index a649c909..6f4397ae 100644 --- a/.github/workflows/swarm.yml +++ b/.github/workflows/swarm.yml @@ -42,6 +42,7 @@ jobs: echo "NEXT_PUBLIC_ENVIRONMENT=SEPOLIA" >> "$GITHUB_ENV" echo "NEXT_PUBLIC_BB_RULES_URL=https://create.fairdatasociety.org/#/bb-rules" >> "$GITHUB_ENV" echo "NEXT_PUBLIC_BB_INVITE_URL_PREFIX=https://create.fairdatasociety.org" >> "$GITHUB_ENV" + echo "NEXT_PUBLIC_BB_API_URL=https://bbapi.fairdatasociety.org" >> "$GITHUB_ENV" echo "PURGE_URL=https://app.fairdrive.fairdatasociety.org" >> "$GITHUB_ENV" echo "SWARM_URL=https://gateway.fairdatasociety.org/proxy/" >> "$GITHUB_ENV" echo "SIGNER=SIGNER_$GITHUB_REF_NAME" >> "$GITHUB_ENV" @@ -58,6 +59,7 @@ jobs: echo "NEXT_PUBLIC_ENVIRONMENT=SEPOLIA" >> "$GITHUB_ENV" echo "NEXT_PUBLIC_BB_RULES_URL=https://create.dev.fairdatasociety.org/#/bb-rules" >> "$GITHUB_ENV" echo "NEXT_PUBLIC_BB_INVITE_URL_PREFIX=https://create.dev.fairdatasociety.org" >> "$GITHUB_ENV" + echo "NEXT_PUBLIC_BB_API_URL=https://bbapi.fairdatasociety.org" >> "$GITHUB_ENV" echo "PURGE_URL=https://app.fairdrive.dev.fairdatasociety.org" >> "$GITHUB_ENV" echo "SWARM_URL=https://gateway.fairdatasociety.org/proxy/" >> "$GITHUB_ENV" echo "SIGNER=SIGNER_$GITHUB_REF_NAME" >> "$GITHUB_ENV" @@ -74,6 +76,7 @@ jobs: echo "NEXT_PUBLIC_ENVIRONMENT=SEPOLIA" >> "$GITHUB_ENV" echo "NEXT_PUBLIC_BB_RULES_URL=https://create.staging.fairdatasociety.org/#/bb-rules" >> "$GITHUB_ENV" echo "NEXT_PUBLIC_BB_INVITE_URL_PREFIX=https://create.staging.fairdatasociety.org" >> "$GITHUB_ENV" + echo "NEXT_PUBLIC_BB_API_URL=https://bbapi.fairdatasociety.org" >> "$GITHUB_ENV" echo "PURGE_URL=https://fairos.staging.fairdatasociety.org" >> "$GITHUB_ENV" echo "SWARM_URL=https://gateway.fairdatasociety.org/proxy/" >> "$GITHUB_ENV" echo "SIGNER=SIGNER_$GITHUB_REF_NAME" >> "$GITHUB_ENV" diff --git a/src/components/Invite/Invite.tsx b/src/components/Invite/Invite.tsx index 003f292a..a0088caf 100644 --- a/src/components/Invite/Invite.tsx +++ b/src/components/Invite/Invite.tsx @@ -7,6 +7,7 @@ import { Invite, makeInviteUrl, saveInviteLocally, + shareInvite, updateInviteLocally, } from '@utils/invite'; import CelebrateImage from '@media/UI/invite/celebrate.png'; @@ -16,6 +17,7 @@ import { TopUpInviteModal } from '@components/Modals'; import { FieldError } from 'react-hook-form/dist/types/errors'; import Invites from '@components/Invites/Invites'; import CustomCheckbox from '@components/Inputs/CustomCheckbox/CustomCheckbox'; +import { useFdpStorage } from '@context/FdpStorageContext'; export const STEP_CREATE = 'create'; export const STEP_FILL = 'fill'; @@ -36,6 +38,7 @@ const Invite: FC = () => { const [invites, setInvites] = useState([]); const [topUpModal, setTopUpModal] = useState(false); const [termsAccepted, setTermsAccepted] = useState(false); + const { wallet } = useFdpStorage(); /** * When user click by Save name button @@ -67,6 +70,9 @@ const Invite: FC = () => { saveInviteLocally(invite); updateInvitesList(); setLoading(false); + if (termsAccepted && wallet) { + shareInvite(wallet.privateKey, invite.invite); + } }); }; diff --git a/src/utils/invite.ts b/src/utils/invite.ts index 805fed6f..8b4b080c 100644 --- a/src/utils/invite.ts +++ b/src/utils/invite.ts @@ -6,6 +6,7 @@ export const INVITES_LOCAL_STORAGE_KEY = 'fd_invites'; export const INVITE_LOCAL_STORAGE_KEY = 'fd_invite'; export const INVITE_NAME_MIN_LENGTH = 1; export const INVITE_NAME_MAX_LENGTH = 255; +export const INVITE_SHARE_URL = `${process.env.NEXT_PUBLIC_BB_API_URL}/v1/invite`; /** * Invite related data @@ -154,3 +155,38 @@ export function saveInvite(invite: string): void { export function getInvite(): string | null { return localStorage.getItem(INVITE_LOCAL_STORAGE_KEY); } + +/** + * Shares invite address with signature of inviter and invite + * + * @param inviterPrivateKey Inviter private key for signing invite address + * @param invitePrivateKey Invite private key for signing inviter address + */ +export async function shareInvite( + inviterPrivateKey: string, + invitePrivateKey: string +): Promise { + const inviterWallet = new Wallet(inviterPrivateKey); + const inviteWallet = new Wallet(invitePrivateKey); + const inviterSignature = await inviterWallet.signMessage( + inviteWallet.address.toLowerCase() + ); + const inviteSignature = await inviteWallet.signMessage( + inviterWallet.address.toLowerCase() + ); + + const data = { + inviter_address: inviterWallet.address.toLowerCase(), + invite_address: inviteWallet.address.toLowerCase(), + inviter_signature: inviterSignature, + invite_signature: inviteSignature, + }; + + await fetch(`${INVITE_SHARE_URL}/create`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(data), + }); +}