mirror of
https://github.com/Discreetly/frontend.git
synced 2026-01-09 12:58:03 -05:00
jubmoji/gateway request fixes
This commit is contained in:
@@ -4,10 +4,11 @@
|
||||
import Creation from 'svelte-material-icons/Creation.svelte';
|
||||
import MagicStaff from 'svelte-material-icons/MagicStaff.svelte';
|
||||
import Loading from '$lib/components/Utils/Loading.svelte';
|
||||
import { alertQueue, configStore } from '$lib/stores';
|
||||
import { alertQueue, configStore, identityExists } from '$lib/stores';
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
let loading = false;
|
||||
let acceptedRoomNames: string[] = [];
|
||||
$: proof = $configStore.signUpStatus.jubmojiProof;
|
||||
|
||||
function validateProof(proof: JubmojiProofI) {
|
||||
@@ -19,7 +20,7 @@
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
console.error(err);
|
||||
alertQueue.enqueue(`Unexpected error: ${err.message}`, 'error');
|
||||
})
|
||||
.finally(() => {
|
||||
@@ -28,8 +29,10 @@
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
if ($configStore.signUpStatus.jubmojiProof) {
|
||||
if ($configStore.signUpStatus.jubmojiProof && $identityExists == 'safe') {
|
||||
validateProof($configStore.signUpStatus.jubmojiProof);
|
||||
} else if ($configStore.signUpStatus.jubmojiProof && $identityExists == 'encrypted') {
|
||||
alertQueue.enqueue('Unlock your identity to claim your Jubmoji Powers', 'warning');
|
||||
}
|
||||
});
|
||||
</script>
|
||||
@@ -49,3 +52,11 @@
|
||||
><Creation class="mr-2" />Harness Your Power<MagicStaff /></a
|
||||
>
|
||||
{/if}
|
||||
{#if acceptedRoomNames.length > 0}
|
||||
<p class="text-center mt-2">You've been added to:</p>
|
||||
<div class="my-2">
|
||||
{#each acceptedRoomNames as name}
|
||||
<ins class="ins border-y border-success-800">{name}</ins>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
import { theWordRequest } from '$lib/gateways/theWord';
|
||||
let files: FileList;
|
||||
let loading = false;
|
||||
let acceptedRoomNames: string[] = [];
|
||||
|
||||
function theWordHandler(proof: any) {
|
||||
loading = true;
|
||||
@@ -61,4 +62,12 @@
|
||||
{#if loading}
|
||||
<Loading />
|
||||
{/if}
|
||||
{#if acceptedRoomNames.length > 0}
|
||||
<p class="text-center mt-2">You've been added to:</p>
|
||||
<div class="my-2">
|
||||
{#each acceptedRoomNames as name}
|
||||
<ins class="ins border-y border-success-800">{name}</ins>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
@@ -20,16 +20,12 @@ export async function handleGatewayRequest<T>(
|
||||
alertQueue.enqueue(`Please Create an Identity`, 'error');
|
||||
return null;
|
||||
}
|
||||
let result;
|
||||
|
||||
try {
|
||||
result = (await apiFunction(server, { ...data, idc })) as JoinResponseI;
|
||||
const result = await apiFunction(server, { ...data, idc });
|
||||
console.debug('GATEWAY RESPONSE: ', result);
|
||||
let acceptedRoomNames: string[];
|
||||
if (!result.status) {
|
||||
alertQueue.enqueue('Error joining room, no status given', 'error');
|
||||
console.warn(result);
|
||||
return null;
|
||||
}
|
||||
|
||||
switch (result.status) {
|
||||
case 'valid':
|
||||
acceptedRoomNames = await updateRooms(server, result.roomIds);
|
||||
@@ -37,7 +33,7 @@ export async function handleGatewayRequest<T>(
|
||||
store['signUpStatus']['completedSignup'] = true;
|
||||
return store;
|
||||
});
|
||||
alertQueue.enqueue(`Accepted into ${acceptedRoomNames}`, 'success');
|
||||
alertQueue.enqueue(`Accepted into ${acceptedRoomNames.join(', ')}`, 'success');
|
||||
return acceptedRoomNames;
|
||||
case 'already-added':
|
||||
alertQueue.enqueue('Already added to room', 'error');
|
||||
|
||||
@@ -80,22 +80,14 @@ export async function postTheWord(
|
||||
serverUrl: string,
|
||||
data: { proof: object; idc: string }
|
||||
): Promise<JoinResponseI> {
|
||||
const response = post([serverUrl, 'gateway/theword/join'], data) as unknown as JoinResponseI;
|
||||
if (!response.status || !response.roomIds) {
|
||||
throw new Error('Response does not match JoinResponseI interface');
|
||||
}
|
||||
return response;
|
||||
return (await post([serverUrl, 'gateway/theword/join'], data)) as Promise<JoinResponseI>;
|
||||
}
|
||||
|
||||
export async function postJubmojis(
|
||||
serverUrl: string,
|
||||
data: { proof: JubmojiProofI; idc: string }
|
||||
): Promise<JoinResponseI> {
|
||||
const response = post([serverUrl, 'gateway/jubmojis/join'], data) as unknown as JoinResponseI;
|
||||
if (!response.status || !response.roomIds) {
|
||||
throw new Error('Response does not match JoinResponseI interface');
|
||||
}
|
||||
return response;
|
||||
return (await post([serverUrl, 'gateway/jubmojis/join'], data)) as Promise<JoinResponseI>;
|
||||
}
|
||||
|
||||
export async function getMessages(serverUrl: string, roomId: string) {
|
||||
|
||||
@@ -197,8 +197,12 @@ export const numberServers = derived(serverStore, ($serverStore) => {
|
||||
export const messagesSent = derived(
|
||||
[currentSelectedRoom, rateLimitStore],
|
||||
([$currentSelectedRoom, $rateLimitStore]) => {
|
||||
if ($currentSelectedRoom.roomId.toString() in $rateLimitStore) {
|
||||
return $rateLimitStore[$currentSelectedRoom.roomId.toString()].messagesSent;
|
||||
if ($currentSelectedRoom && $rateLimitStore) {
|
||||
if ($currentSelectedRoom.roomId.toString() in $rateLimitStore) {
|
||||
return $rateLimitStore[$currentSelectedRoom.roomId.toString()].messagesSent;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user