Skip to content

Commit 68f0281

Browse files
authored
Merge pull request #385 from algorandfoundation/hotfix/fix-algosdk3-behaviour-differences
fix: resolve some algosdk@3 behaviour differences
2 parents 59052b7 + 80b9a99 commit 68f0281

File tree

4 files changed

+43
-24
lines changed

4 files changed

+43
-24
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"postinstall": "patch-package"
2525
},
2626
"dependencies": {
27-
"@algorandfoundation/algokit-subscriber": "3.0.1",
27+
"@algorandfoundation/algokit-subscriber": "^3.0.2",
2828
"@algorandfoundation/algokit-utils": "^8.1.0",
2929
"@auth0/auth0-react": "^2.2.4",
3030
"@blockshake/defly-connect": "^1.2.1",
@@ -197,4 +197,4 @@
197197
"overrides": {
198198
"ws@>7.0.0 <7.5.9": "7.5.10"
199199
}
200-
}
200+
}

src/features/abi-methods/utils/parse-errors.ts

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { getApplicationResultAtom } from '@/features/applications/data'
22
import { dataStore } from '@/features/common/data/data-store'
3+
import { asAlgosdkTransactions } from '@/features/transaction-wizard/mappers'
34
import { BuildableTransactionType, BuildMethodCallTransactionResult, BuildTransactionResult } from '@/features/transaction-wizard/models'
45
import { asError } from '@/utils/error'
56
import { AppClient } from '@algorandfoundation/algokit-utils/types/app-client'
@@ -8,12 +9,7 @@ import algosdk from 'algosdk'
89
type URLTokenBaseHTTPError = {
910
name: 'URLTokenBaseHTTPError'
1011
response: {
11-
body: {
12-
data: {
13-
['app-index']: number
14-
['group-index']: number
15-
}
16-
}
12+
text: string
1713
}
1814
}
1915

@@ -23,26 +19,49 @@ type SimulateError = Error & {
2319

2420
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2521
const isURLTokenBaseHTTPError = (e: any): e is URLTokenBaseHTTPError => {
26-
return (
27-
e.name === 'URLTokenBaseHTTPError' &&
28-
e.response?.body?.data &&
29-
e.response.body.data['app-index'] !== undefined &&
30-
e.response.body.data['group-index'] !== undefined
31-
)
22+
return e.name === 'URLTokenBaseHTTPError' && e.response?.text
3223
}
3324

3425
// eslint-disable-next-line @typescript-eslint/no-explicit-any
3526
const isSimulateError = (e: any): e is SimulateError => {
3627
return e.simulateResponse !== undefined
3728
}
3829

30+
/**
31+
* The supplied transactions array may contain transactions passed as ABI method call args, which become group transactions.
32+
* This function flattens any such args into the transaction group and finds the transaction by group index.
33+
*/
34+
const findTransactionInGroup = async (transactions: BuildTransactionResult[], groupIndex: number) => {
35+
const indexMap: number[] = []
36+
37+
for (const [i, transaction] of transactions.entries()) {
38+
// Flattens out transactions passed as ABI method call args
39+
const txns = await asAlgosdkTransactions(transaction)
40+
txns.forEach((_) => {
41+
indexMap.push(i)
42+
})
43+
}
44+
45+
const index = indexMap[groupIndex]
46+
if (index === undefined) {
47+
return undefined
48+
}
49+
return transactions[index]
50+
}
51+
3952
export const parseCallAbiMethodError = async (e: unknown, transactions: BuildTransactionResult[]): Promise<Error> => {
4053
if (!isURLTokenBaseHTTPError(e)) {
4154
return asError(e)
4255
}
4356

44-
const groupIndex = e.response.body.data['group-index']
45-
const transaction = transactions[groupIndex]
57+
const errorBody = JSON.parse(e.response.text)
58+
const groupIndex =
59+
errorBody && errorBody.data && errorBody.data['group-index'] !== undefined ? (errorBody.data['group-index'] as number) : undefined
60+
if (groupIndex === undefined) {
61+
return asError(e)
62+
}
63+
64+
const transaction = await findTransactionInGroup(transactions, groupIndex)
4665
if (!transaction || transaction.type !== BuildableTransactionType.MethodCall) {
4766
return asError(e)
4867
}
@@ -62,7 +81,7 @@ export const parseSimulateAbiMethodError = async (e: unknown, transactions: Buil
6281

6382
// When there are multiple errors, the failedAt array will only have one element
6483
const groupIndex = Number(e.simulateResponse.txnGroups[0].failedAt[0])
65-
const transaction = transactions[groupIndex]
84+
const transaction = await findTransactionInGroup(transactions, groupIndex)
6685
if (!transaction || transaction.type !== BuildableTransactionType.MethodCall) {
6786
return asError(e)
6887
}
@@ -91,7 +110,7 @@ const parseErrorForTransaction = async (e: unknown, groupIndex: number, transact
91110
return asError(e)
92111
}
93112

94-
return new Error(`Error in transaction ${groupIndex + 1}: ${tealErrorMessage}`)
113+
return new Error(`Error in transaction at index ${groupIndex}: ${tealErrorMessage}`)
95114
}
96115

97116
const extractErrorMessage = (errorString: string): string | undefined => {

src/features/transaction-wizard/utils/transform-search-params-transactions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ export function transformSearchParamsTransactions(searchParamTransactions: BaseS
5252
} catch (error) {
5353
if (error instanceof z.ZodError) {
5454
const badPaths = error.errors.map((e) => e.path.join('-'))
55-
errors.push(`Error in transaction ${index} in the following fields: ${badPaths.join(', ')}`)
55+
errors.push(`Error in transaction at index ${index} in the following fields: ${badPaths.join(', ')}`)
5656
continue
5757
}
5858
if (error instanceof Error) {
59-
errors.push(`Error in transaction ${index}: ${error.message}`)
59+
errors.push(`Error in transaction at index ${index}: ${error.message}`)
6060
}
6161
}
6262
}

0 commit comments

Comments
 (0)