Skip to content

Commit

Permalink
refactor: info modal for copied alert
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorShadurin committed Jun 10, 2023
1 parent c34aa7a commit 44621cb
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .example.env.local
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions .github/workflows/buildx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
3 changes: 3 additions & 0 deletions .github/workflows/swarm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions src/components/Invite/Invite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
Invite,
makeInviteUrl,
saveInviteLocally,
shareInvite,
updateInviteLocally,
} from '@utils/invite';
import CelebrateImage from '@media/UI/invite/celebrate.png';
Expand All @@ -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';
Expand All @@ -36,6 +38,7 @@ const Invite: FC<InviteProps> = () => {
const [invites, setInvites] = useState<Invite[]>([]);
const [topUpModal, setTopUpModal] = useState<boolean>(false);
const [termsAccepted, setTermsAccepted] = useState<boolean>(false);
const { wallet } = useFdpStorage();

/**
* When user click by Save name button
Expand Down Expand Up @@ -67,6 +70,9 @@ const Invite: FC<InviteProps> = () => {
saveInviteLocally(invite);
updateInvitesList();
setLoading(false);
if (termsAccepted && wallet) {
shareInvite(wallet.privateKey, invite.invite);
}
});
};

Expand Down
36 changes: 36 additions & 0 deletions src/utils/invite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<void> {
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),
});
}

0 comments on commit 44621cb

Please sign in to comment.