From 7cbb4e948cf0891935562c8a36a16ab966ff0023 Mon Sep 17 00:00:00 2001 From: daryl Date: Wed, 25 Oct 2023 11:04:49 +0800 Subject: [PATCH] feat(sudt): add explorer service --- .../sudt/src/services/explorer.service.ts | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 packages/samples/sudt/src/services/explorer.service.ts diff --git a/packages/samples/sudt/src/services/explorer.service.ts b/packages/samples/sudt/src/services/explorer.service.ts new file mode 100644 index 000000000..e000bcc6a --- /dev/null +++ b/packages/samples/sudt/src/services/explorer.service.ts @@ -0,0 +1,32 @@ +export class ExplorerService { + constructor(private host = '') {} + + updateSUDT = async (params: { + typeHash: string + symbol: string + fullName: string + decimal: string + totalAmount: string + description: string + operatorWebsite: string + iconFile: string + uan: string + displayName: string + email: string + token?: string + }) => { + const res = await fetch(`${this.host}/api/v1/udts/${params.typeHash}`, { method: 'POST', body: JSON.stringify({}) }) + if (!res.ok) { + throw new Error('Internal Service Error') + } + + switch (Math.ceil(res.status / 100)) { + case 2: + return true + case 3: + throw new Error('Redirect') + case 4: + throw new Error('Client Error') + } + } +}