Skip to content

Commit

Permalink
test api
Browse files Browse the repository at this point in the history
  • Loading branch information
KorbinianK committed May 2, 2024
1 parent 38abb63 commit ddce785
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
22 changes: 22 additions & 0 deletions packages/bridge-ui/src/components/Bridge/FungibleBridge.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,26 @@
stepDescription = $t(`bridge.description.fungible.${stepKey}`);
}
}

const testApi = () => {
// eslint-disable-next-line no-console
console.log('test');
// fetch from /api/test via get
fetch('/api/test', {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
})
.then((response) => response.json())
.then((data) => {
// eslint-disable-next-line no-console
console.log(data);
})
.catch((error) => {
console.error('Error:', error);
});
};
</script>

<div class=" gap-0 w-full md:w-[524px]">
Expand All @@ -41,6 +61,8 @@
>{$t('bridge.step.confirm.title')}</Step>
</Stepper>

<button on:click={() => testApi()}>Test</button>

<Card class="md:mt-[32px] w-full md:w-[524px]" title={stepTitle} text={stepDescription}>
<div class="space-y-[30px] mt-[30px]">
{#if activeStep === BridgeSteps.IMPORT}
Expand Down
18 changes: 18 additions & 0 deletions packages/bridge-ui/src/routes/api/test/+server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { error } from '@sveltejs/kit';

import type { RequestHandler } from './$types';

export const GET: RequestHandler = ({ url }) => {
const min = Number(url.searchParams.get('min') ?? '0');
const max = Number(url.searchParams.get('max') ?? '1');

const d = max - min;

if (isNaN(d) || d < 0) {
error(400, 'min and max must be numbers, and min must be less than max');
}

const random = min + Math.random() * d;

return new Response(String(random));
};

0 comments on commit ddce785

Please sign in to comment.