From 194f6def1813f7b84ff7c62736db593f1b8a0e27 Mon Sep 17 00:00:00 2001 From: Sergej Date: Sun, 11 Aug 2024 12:27:26 +0200 Subject: [PATCH 1/3] request_region_record fix --- .../Regions/IsmpRegionCard/index.tsx | 45 ++++++++----------- src/models/common/consts.ts | 2 +- src/utils/functions/api.ts | 27 +++++++++++ 3 files changed, 47 insertions(+), 27 deletions(-) diff --git a/src/components/Regions/IsmpRegionCard/index.tsx b/src/components/Regions/IsmpRegionCard/index.tsx index 20c78a6f..1b2a7be6 100644 --- a/src/components/Regions/IsmpRegionCard/index.tsx +++ b/src/components/Regions/IsmpRegionCard/index.tsx @@ -14,7 +14,7 @@ import en from 'javascript-time-ago/locale/en'; import { useEffect, useState } from 'react'; import { useSubmitExtrinsic } from '@/hooks/submitExtrinsic'; -import { timesliceToTimestamp } from '@/utils/functions'; +import { sendUnsignedTx, timesliceToTimestamp } from '@/utils/functions'; import { makeResponse, makeTimeout, queryRequest } from '@/utils/ismp'; import { useAccounts } from '@/contexts/account'; @@ -183,31 +183,24 @@ export const IsmpRegionCard = ({ region.getRegionId() ); setWorking(true); - submitExtrinsicWithFeeInfo( - regionxSymbol, - regionxDecimals, - request, - activeAccount.address, - activeSigner, - { - ready: () => toastInfo('Transaction was initiated'), - inBlock: () => toastInfo('In Block'), - finalized: () => { - /** */ - }, - success: () => { - toastSuccess('Transaction successful'); - setWorking(false); - fetchRegions(); - }, - fail: () => { - toastError(`Failed to request region record`); - }, - error: (e) => { - toastError(`Failed to request the region record. ${e}`); - }, - } - ); + sendUnsignedTx(request, { + ready: () => toastInfo('Transaction was initiated'), + inBlock: () => toastInfo('In Block'), + finalized: () => { + /** */ + }, + success: () => { + toastSuccess('Transaction successful'); + setWorking(false); + fetchRegions(); + }, + fail: () => { + toastError(`Failed to request region record`); + }, + error: (e) => { + toastError(`Failed to request the region record. ${e}`); + }, + }); }; return ( diff --git a/src/models/common/consts.ts b/src/models/common/consts.ts index 01414f98..7a0d01b3 100644 --- a/src/models/common/consts.ts +++ b/src/models/common/consts.ts @@ -18,7 +18,7 @@ export const WEEK_IN_TIMESLICES = DAY_IN_TIMESLICES * 7; export const REGION_COLLECTION_ID = 42; export const CORETIME_PARA_ID = 1005; -export const REGIONX_PARA_ID = 4479; +export const REGIONX_PARA_ID = 2000; export const SAFE_XCM_VERSION = 3; diff --git a/src/utils/functions/api.ts b/src/utils/functions/api.ts index eb3a36cd..a674dc35 100644 --- a/src/utils/functions/api.ts +++ b/src/utils/functions/api.ts @@ -37,6 +37,33 @@ export const sendTx = async ( } }; +export const sendUnsignedTx = async ( + tx: SubmittableExtrinsic<'promise', ISubmittableResult>, + handlers: TxStatusHandlers +) => { + try { + const unsub = await tx.send(({ status, events }) => { + if (status.isReady) handlers.ready(); + else if (status.isInBlock) handlers.inBlock(); + else if (status.isFinalized) { + handlers.finalized(); + events.forEach(({ event: { method } }) => { + if (method === 'ExtrinsicSuccess') { + handlers.success(); + } else if (method === 'ExtrinsicFailed') { + handlers.fail(); + } + }); + unsub(); + } + }); + } catch (e) { + handlers.error(e); + } finally { + handlers.finally && handlers.finally(); + } +}; + export const enableRegionX = (network: NetworkType): boolean => { return network === NetworkType.ROCOCO || EXPERIMENTAL; }; From 541c38664b599d80e8d492e7f15a0d948f041a3b Mon Sep 17 00:00:00 2001 From: Sergej Date: Sun, 11 Aug 2024 12:30:12 +0200 Subject: [PATCH 2/3] fix para id --- src/models/common/consts.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/models/common/consts.ts b/src/models/common/consts.ts index 7a0d01b3..01414f98 100644 --- a/src/models/common/consts.ts +++ b/src/models/common/consts.ts @@ -18,7 +18,7 @@ export const WEEK_IN_TIMESLICES = DAY_IN_TIMESLICES * 7; export const REGION_COLLECTION_ID = 42; export const CORETIME_PARA_ID = 1005; -export const REGIONX_PARA_ID = 2000; +export const REGIONX_PARA_ID = 4479; export const SAFE_XCM_VERSION = 3; From 3fdf480156a2902a3824c4ae3c618cd8366ce8b6 Mon Sep 17 00:00:00 2001 From: Sergej Date: Sun, 11 Aug 2024 12:32:50 +0200 Subject: [PATCH 3/3] lint --- src/components/Regions/IsmpRegionCard/index.tsx | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/components/Regions/IsmpRegionCard/index.tsx b/src/components/Regions/IsmpRegionCard/index.tsx index 1b2a7be6..2939170b 100644 --- a/src/components/Regions/IsmpRegionCard/index.tsx +++ b/src/components/Regions/IsmpRegionCard/index.tsx @@ -13,7 +13,6 @@ import TimeAgo from 'javascript-time-ago'; import en from 'javascript-time-ago/locale/en'; import { useEffect, useState } from 'react'; -import { useSubmitExtrinsic } from '@/hooks/submitExtrinsic'; import { sendUnsignedTx, timesliceToTimestamp } from '@/utils/functions'; import { makeResponse, makeTimeout, queryRequest } from '@/utils/ismp'; @@ -48,12 +47,7 @@ export const IsmpRegionCard = ({ timeslicePeriod, } = useCoretimeApi(); const { - state: { - api: regionxApi, - apiState: regionxApiState, - symbol: regionxSymbol, - decimals: regionxDecimals, - }, + state: { api: regionxApi, apiState: regionxApiState }, } = useRegionXApi(); const { state: { activeAccount, activeSigner }, @@ -67,7 +61,6 @@ export const IsmpRegionCard = ({ const { region, coreOccupancy, status } = regionMetadata; const { toastWarning, toastSuccess, toastInfo, toastError } = useToast(); - const { submitExtrinsicWithFeeInfo } = useSubmitExtrinsic(); const [working, setWorking] = useState(false); useEffect(() => {