From bc1d40e94576cd98ea1369c37f881afcc47d7d7c Mon Sep 17 00:00:00 2001 From: Jaco Date: Tue, 19 Dec 2023 14:28:48 +0200 Subject: [PATCH] Disable claims (non-working) (#10116) * Disable claims (non-working) * Disable on no buffer --- packages/apps-routing/src/claims.ts | 26 +++++++++++++++++++++++++- packages/apps/src/index.tsx | 1 + packages/apps/src/initBufferHack.ts | 13 +++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 packages/apps/src/initBufferHack.ts diff --git a/packages/apps-routing/src/claims.ts b/packages/apps-routing/src/claims.ts index 51166cce66..fd4d03f2ae 100644 --- a/packages/apps-routing/src/claims.ts +++ b/packages/apps-routing/src/claims.ts @@ -4,6 +4,29 @@ import type { Route, TFunction } from './types.js'; import Component, { useCounter } from '@polkadot/app-claims'; +import { hasBuffer, u8aToBuffer } from '@polkadot/util'; + +// See https://github.com/polkadot-js/apps/issues/10115 - this may not work, +// if not we will have to disable it all (no way of testing) +function needsApiCheck (): boolean { + try { + if (!Buffer.from([1, 2, 3])?.length) { + console.error('ERROR: Unable to construct Buffer object for claims module'); + + return false; + } else if (!hasBuffer || !Buffer.isBuffer(u8aToBuffer(new Uint8Array([1, 2, 3])))) { + console.error('ERROR: Unable to use u8aToBuffer for claims module'); + + return false; + } + } catch { + console.error('ERROR: Fatal error in working with Buffer module'); + + return false; + } + + return true; +} export default function create (t: TFunction): Route { return { @@ -12,7 +35,8 @@ export default function create (t: TFunction): Route { needsAccounts: true, needsApi: [ 'tx.claims.mintClaim' - ] + ], + needsApiCheck }, group: 'accounts', icon: 'star', diff --git a/packages/apps/src/index.tsx b/packages/apps/src/index.tsx index c19e68660a..0003e68099 100644 --- a/packages/apps/src/index.tsx +++ b/packages/apps/src/index.tsx @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // setup these right at front +import './initBufferHack.js'; import './initSettings.js'; import 'semantic-ui-css/semantic.min.css'; import '@polkadot/react-components/i18n'; diff --git a/packages/apps/src/initBufferHack.ts b/packages/apps/src/initBufferHack.ts new file mode 100644 index 0000000000..9eceef029e --- /dev/null +++ b/packages/apps/src/initBufferHack.ts @@ -0,0 +1,13 @@ +// Copyright 2017-2023 @polkadot/apps authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import { xglobal } from '@polkadot/x-global'; + +try { + // HACK: Construct a Buffer to ensure that it is actually available in our context + if (Buffer.from([1, 2, 3]).length === 3) { + xglobal.Buffer = Buffer; + } +} catch { + // ignore +}