diff --git a/infra/rooch-portal-v2/src/sections/mint/utils/get-token-info.ts b/infra/rooch-portal-v2/src/sections/mint/utils/get-token-info.ts index 124c0e2f4c..dfeaa6ed82 100644 --- a/infra/rooch-portal-v2/src/sections/mint/utils/get-token-info.ts +++ b/infra/rooch-portal-v2/src/sections/mint/utils/get-token-info.ts @@ -18,7 +18,11 @@ export type TokenInfo = { function extractCoinInfoContent(input: string): string | null { const regex = /CoinInfo<([^>]+)>/; - const match = input.match(regex); + let match; + + if (input) { + match = input.match(regex); + } if (match && match[1]) { return match[1]; @@ -38,11 +42,15 @@ export async function getTokenInfo( showDisplay: true, }, }); - const decode = (((data[0].decoded_value as any).value as any).value as any).value as any; - const coinInfo = decode.coin_info as AnnotatedMoveStructView; - const coinId = coinInfo.value.id as string; + const decode = (((data?.[0]?.decoded_value as any)?.value as any)?.value as any)?.value as any; + const coinInfo = decode?.coin_info as AnnotatedMoveStructView; + const coinId = coinInfo?.value?.id as string; - const coinType = extractCoinInfoContent(coinInfo.type)!; + const coinType = extractCoinInfoContent(coinInfo?.type)!; + + if (!coinId) { + return undefined; + } return client .getStates({ @@ -53,7 +61,7 @@ export async function getTokenInfo( }, }) .then((sv) => { - const coinView = (sv[0].decoded_value as any).value as any; + const coinView = (sv?.[0]?.decoded_value as any)?.value as any; const starTime = decode.start_time as number; const endTime = decode.end_time as number; const now = Date.now() / 1000; diff --git a/infra/rooch-portal-v2/src/sections/red-envelope/detail/view.tsx b/infra/rooch-portal-v2/src/sections/red-envelope/detail/view.tsx index e4e92ebc47..87dbfccb0e 100644 --- a/infra/rooch-portal-v2/src/sections/red-envelope/detail/view.tsx +++ b/infra/rooch-portal-v2/src/sections/red-envelope/detail/view.tsx @@ -48,7 +48,7 @@ export default function RedEnvelopeDetail({ redEnvelopeId }: { redEnvelopeId: st console.log('🚀 ~ file: view.tsx:21 ~ RedEnvelopeDetail ~ data:', redEnvelopeObject); const redEnvelopeInfo = useMemo(() => { - const info = redEnvelopeObject?.data[0].decoded_value?.value as unknown as + const info = redEnvelopeObject?.data?.[0]?.decoded_value?.value as unknown as | RedEnvelopeItem | undefined; return info; diff --git a/sdk/typescript/bitseed-sdk/src/datasource/rooch/rooch_datasource.ts b/sdk/typescript/bitseed-sdk/src/datasource/rooch/rooch_datasource.ts index 19b81ff86a..382efcba74 100644 --- a/sdk/typescript/bitseed-sdk/src/datasource/rooch/rooch_datasource.ts +++ b/sdk/typescript/bitseed-sdk/src/datasource/rooch/rooch_datasource.ts @@ -331,7 +331,7 @@ export class RoochDataSource implements IDatasource { throw new Error(`Transaction with id ${txId} not found`) } - const btcTxOption = txResult.return_values[0].decoded_value.value.vec[0] + const btcTxOption = txResult.return_values?.[0]?.decoded_value?.value?.vec?.[0] if (!btcTxOption) { throw new Error(`Transaction with id ${txId} not found`) } diff --git a/sdk/typescript/rooch-sdk/src/client/client.ts b/sdk/typescript/rooch-sdk/src/client/client.ts index 19719621bb..d59a9f3fbb 100644 --- a/sdk/typescript/rooch-sdk/src/client/client.ts +++ b/sdk/typescript/rooch-sdk/src/client/client.ts @@ -258,7 +258,7 @@ export class RoochClient { }) if (resp && resp.return_values) { - return BigInt(resp.return_values[0].decoded_value as number) + return BigInt(resp.return_values?.[0]?.decoded_value as number) } return BigInt(0) @@ -335,7 +335,7 @@ export class RoochClient { }) if (result.vm_status === 'Executed' && result.return_values) { - const value = (result.return_values[0].decoded_value as AnnotatedMoveStructView).value + const value = (result.return_values?.[0]?.decoded_value as AnnotatedMoveStructView).value const address = (((value as any).vec[0] as AnnotatedMoveStructView).value as any).bytes @@ -386,7 +386,7 @@ export class RoochClient { throw new Error('view 0x3::session_key::is_expired_session_key fail') } - return result.return_values![0].decoded_value as boolean + return result.return_values![0]?.decoded_value as boolean } async getSessionKeys({ @@ -416,7 +416,7 @@ export class RoochClient { const tableId = ( ( ( - (states[0].decoded_value as AnnotatedMoveStructView).value[ + (states?.[0]?.decoded_value as AnnotatedMoveStructView).value[ 'value' ] as AnnotatedMoveStructView ).value['keys'] as AnnotatedMoveStructView @@ -450,7 +450,7 @@ export class RoochClient { const result = new Array() for (const state of statePage.data as any) { - const moveValue = state?.state.decoded_value as any + const moveValue = state?.state?.decoded_value as any if (moveValue) { const val = moveValue.value.value.value