diff options
| author | Adam Soltys <[email protected]> | 2023-05-10 14:05:26 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2023-05-10 14:05:26 -0700 |
| commit | 7974e1565a0dc3a1809d84fefc1feb90b0d83383 (patch) | |
| tree | 2593b330cac19745671d3fc142985b2df959d46a | |
| parent | 092fe68e09434ed290bcb0e1b8076d3852901e5f (diff) | |
| download | coinos-ui-7974e1565a0dc3a1809d84fefc1feb90b0d83383.tar.gz coinos-ui-7974e1565a0dc3a1809d84fefc1feb90b0d83383.zip | |
update docs
| -rw-r--r-- | src/components/Code.svelte | 4 | ||||
| -rw-r--r-- | src/lib/samples.js | 59 | ||||
| -rw-r--r-- | src/lib/utils.js | 6 | ||||
| -rw-r--r-- | src/routes/(static)/docs/+page.svelte | 63 |
4 files changed, 97 insertions, 35 deletions
diff --git a/src/components/Code.svelte b/src/components/Code.svelte index a718c5ed..dd0cecf2 100644 --- a/src/components/Code.svelte +++ b/src/components/Code.svelte @@ -1,5 +1,5 @@ <script> - import { copy } from '$lib/utils'; + import { copyNoNewlines as copy } from '$lib/utils'; import { Icon } from '$comp'; import samples from '$lib/samples'; export let sample; @@ -11,7 +11,7 @@ </div> <button class="ml-auto my-auto invert opacity-90" - on:click={() => copy(samples[sample].replace(/^\s+/gm, '').replace(/\n/g, ''))} + on:click={() => copy(samples[sample])} ><Icon icon="copy" style="w-10 max-w-none" /></button > </div> diff --git a/src/lib/samples.js b/src/lib/samples.js index 14d9e4e0..0b447d06 100644 --- a/src/lib/samples.js +++ b/src/lib/samples.js @@ -1,32 +1,69 @@ export default { - register: `curl "https://coinos.io/api/register" -H "application/json" -d '{ - "username": "adam", + register: `curl "https://coinos.io/api/register" -H "content-type: application/json" -d '{ + "username": "demo", "password": "hunter2" }'`, - login: `curl "https://coinos.io/api/login" -H "application/json" -d '{ - "username": "adam", + login: `curl "https://coinos.io/api/login" -H "content-type: application/json" -d '{ + "username": "demo", "password": "hunter2" }'`, payments: `curl "https://coinos.io/api/payments" - -H "application/json" + -H "content-type: application/json" -H "Authorization: Bearer $token" +`, + lightning: `curl "https://coinos.io/api/payments" + -H "content-type: application/json" + -H "Authorization: Bearer $token" + -d '{ + "payreq": "lnbc1pj94d8fsp5n77k340ps4m9jn7kp8he8yynpddvurv6mcsrrqpnq5l2jxdxzlwqpp5m96pqhc5nrlk8cqsu9ufdxxa43sarp8vwf9egvm2pg9nl0zu9r8qdq2vdhkjmn0wvxqztgcqpjrzjqwhmav82kntsppmkp8jp4vg4h9nns78tsy8mg7ve4lq5txrkp0h56zlarvqqdtcqqsqqqqqqqqqqp6cq9q9qyysgqzxlypywzphyujm3ga5j5csfcmqvlnae0fgnvymkaaw94eeg7py5rqzysyjkr3ev2snq63qpsc69vf54adkd0szvmvwt5cuadjnuy95sq4xfa40" +}'`, + bitcoin: `curl "https://coinos.io/api/payments" + -H "content-type: application/json" + -H "Authorization: Bearer $token" + -d '{ + "amount": 5000, + "hash": "bc1q3unh97w4rmelflrm2hvdwz37d8kray3vn4d5ca" +}'`, + internal: `curl "https://coinos.io/api/payments" + -H "content-type: application/json" + -H "Authorization: Bearer $token" + -d '{ + "amount": 5000, + "username": "alice" }'`, rates: `curl "https://coinos.io/api/rates" - -H "application/json" + -H "content-type: application/json" }'`, - invoice: `curl "https://coinos.io/api/invoice" - -H "application/json" + lightningInvoice: `curl "https://coinos.io/api/invoice" + -H "content-type: application/json" -H "Authorization: Bearer $token" -d '{ "invoice": { "amount": 1000, + "type": "lightning" + } +}'`, + bitcoinAddress: `curl "https://coinos.io/api/invoice" + -H "content-type: application/json" + -H "Authorization: Bearer $token" + -d '{ + "invoice": { + "amount": 3141, + "type": "bitcoin" + } +}'`, + webhook: `curl "https://coinos.io/api/invoice" + -H "content-type: application/json" + -H "Authorization: Bearer $token" + -d '{ + "invoice": { "type": "lightning", "webhook": "https://example.com/payment/received", - "secret": "hunter2" - }, + "secret": "webhooksecret" + } }'`, fetchInvoice: `curl "https://coinos.io/api/invoice/bc1qmhfk9stzffhd9umzmld92vff7zg3mdlh7rvvaj" - -H "application/json"'`, + -H "content-type: application/json"'`, invoiceResponse: `{ "amount":3141 "tip":0 diff --git a/src/lib/utils.js b/src/lib/utils.js index 69606d36..70ea5d3b 100644 --- a/src/lib/utils.js +++ b/src/lib/utils.js @@ -74,6 +74,12 @@ export let copy = (text) => { success('Copied!'); }; +export let copyNoNewlines = (text) => { + let stripped = text.replace(/\n/g, ' ').replace(/\s+/g, ' '); + navigator.clipboard.writeText(stripped); + success('Copied!'); +}; + export function reverseFormat(val, locale) { let parts = new Intl.NumberFormat(locale).formatToParts(1111.1); let group = parts.find((part) => part.type === 'group').value; diff --git a/src/routes/(static)/docs/+page.svelte b/src/routes/(static)/docs/+page.svelte index e453464c..86be02f0 100644 --- a/src/routes/(static)/docs/+page.svelte +++ b/src/routes/(static)/docs/+page.svelte @@ -1,12 +1,12 @@ <script> - import { copy } from '$lib/utils'; + import { copyNoNewlines as copy } from '$lib/utils'; import { Code, Icon } from '$comp'; import { PUBLIC_COINOS_URL } from '$env/static/public'; export let data; let { user, token } = data; let api = 'https://coinos.io/api'; - let tokenSample = `export token="${token}"`; + let tokenSample = token ? `export token="${token}"` : `export token=<your auth token>`; </script> <div class="space-y-8 lg:text-xl mt-20 pt-20 md:pt-0 w-full max-w-full"> @@ -14,10 +14,10 @@ <p class="text-secondary"> Coinos has a simple REST API that can be used to register accounts and make payments and - queries. + queries. The following examples show how you can call the API with <a href="https://curl.se/" class="font-bold">curl</a> from your command line. </p> - <h2 class="text-2xl">Base URL</h2> + <h2 class="text-2xl">API Base URL</h2> <div class="bg-black text-white rounded-lg p-4 flex gap-4"> <div>{api}</div> <button class="ml-auto my-auto invert opacity-90" on:click={() => copy(api)} @@ -25,16 +25,23 @@ > </div> - {#if token} - <h2 class="text-2xl">Auth Token</h2> - <p class="text-secondary">This token authorizes you to use the API as <b>{user.username}</b></p> - <div class="bg-black text-white rounded-lg p-4 flex gap-4"> - <div class="w-full break-all">{tokenSample}</div> - <button class="ml-auto my-auto invert opacity-90" on:click={() => copy(tokenSample)} - ><Icon icon="copy" style="w-10 max-w-none" /></button - > - </div> - {/if} + <h2 class="text-2xl">Auth Token</h2> + <p class="text-secondary"> + {#if user && token} + This token authorizes you to use the API as <b>{user.username}</b>. + {:else} + <a href="/login" class="font-bold">Sign in</a> to view your auth token here, or get one from the /login endpoint. + {/if} + + Save it in a variable called <b>$token</b> to run the examples. + </p> + + <div class="bg-black text-white rounded-lg p-4 flex gap-4"> + <div class="w-full break-all">{tokenSample}</div> + <button class="ml-auto my-auto invert opacity-90" on:click={() => copy(tokenSample)} + ><Icon icon="copy" style="w-10 max-w-none" /></button + > + </div> <h2 class="text-2xl">POST /register</h2> <p class="text-secondary">Register a new user account with a username and password</p> @@ -61,11 +68,19 @@ </div> </div> - <Code sample="invoice" /> + <p>Get a lightning invoice to receive funds</p> + <Code sample="lightningInvoice" /> + + <p>Get a bitcoin address to receive funds</p> + <Code sample="bitcoinAddress" /> <p>Sample response</p> <Code sample="invoiceResponse" /> - <p>You can check the <b>received</b> field to see how many satoshis have been paid so far</p> + <p>You can check the <b>received</b> field to see how much has been paid</p> + + + <p>Specify a webhook to be called when an invoice is paid</p> + <Code sample="webhook" /> <h2 class="text-2xl">GET /invoice/:hash</h2> <p class="text-secondary"> @@ -73,6 +88,16 @@ </p> <Code sample="fetchInvoice" /> + <h2 class="text-2xl">POST /payments</h2> + <p class="text-secondary">Send a lightning payment</p> + <Code sample="lightning" /> + + <p class="text-secondary">Send a bitcoin payment</p> + <Code sample="bitcoin" /> + + <p class="text-secondary">Send an internal payment to another user</p> + <Code sample="internal" /> + <h2 class="text-2xl">GET /payments</h2> <p class="text-secondary">Get all payments sent or received by the current user</p> @@ -90,10 +115,4 @@ </div> </div> <Code sample="payments" /> - - <h2 class="text-2xl">Websocket API</h2> - <p class="text-secondary">Subscribe to real time rates and payments</p> - - <div>Authenticate</div> - <Code sample="socketAuth" /> </div> |
