Skip to content

Commit 16da4e4

Browse files
Adds more explicit type guard/null check to account for data sometimes coming back as "null"
1 parent 7bc35d8 commit 16da4e4

2 files changed

Lines changed: 27 additions & 9 deletions

File tree

bun.lock

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

src/actions/transfer.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@ export class TransferAction {
1919
constructor(private walletProvider: WalletProvider) {}
2020

2121
async transfer(params: TransferParams): Promise<Transaction> {
22-
if (!params.data) {
22+
// Normalize empty or invalid data field to '0x'
23+
if (!params.data || params.data === '0x') {
2324
params.data = '0x';
25+
} else {
26+
// Handle case where template returns 'null' string
27+
params.data = (params.data as string) === 'null' ? '0x' : params.data;
2428
}
2529

2630
const walletClient = this.walletProvider.getWalletClient(params.fromChain);
@@ -46,7 +50,8 @@ export class TransferAction {
4650
data: params.data as Hex,
4751
};
4852
} catch (error: unknown) {
49-
const errorMessage = error instanceof Error ? error.message : String(error);
53+
const errorMessage =
54+
error instanceof Error ? error.message : String(error);
5055
throw new Error(`Transfer failed: ${errorMessage}`);
5156
}
5257
}
@@ -84,7 +89,9 @@ const buildTransferDetails = async (
8489
const parsedXml = parseKeyValueXml(xmlResponse);
8590

8691
if (!parsedXml) {
87-
throw new Error('Failed to parse XML response from LLM for transfer details.');
92+
throw new Error(
93+
'Failed to parse XML response from LLM for transfer details.'
94+
);
8895
}
8996

9097
const transferDetails = parsedXml as unknown as TransferParams;
@@ -128,7 +135,12 @@ export const transferAction: Action = {
128135
const action = new TransferAction(walletProvider);
129136

130137
// Compose transfer context
131-
const paramOptions = await buildTransferDetails(state, message, runtime, walletProvider);
138+
const paramOptions = await buildTransferDetails(
139+
state,
140+
message,
141+
runtime,
142+
walletProvider
143+
);
132144

133145
try {
134146
const transferResp = await action.transfer(paramOptions);
@@ -146,7 +158,8 @@ export const transferAction: Action = {
146158
}
147159
return true;
148160
} catch (error: unknown) {
149-
const errorMessage = error instanceof Error ? error.message : String(error);
161+
const errorMessage =
162+
error instanceof Error ? error.message : String(error);
150163
console.error('Error during token transfer:', errorMessage);
151164
if (callback) {
152165
callback({
@@ -179,5 +192,10 @@ export const transferAction: Action = {
179192
},
180193
],
181194
],
182-
similes: ['EVM_TRANSFER', 'EVM_SEND_TOKENS', 'EVM_TOKEN_TRANSFER', 'EVM_MOVE_TOKENS'],
195+
similes: [
196+
'EVM_TRANSFER',
197+
'EVM_SEND_TOKENS',
198+
'EVM_TOKEN_TRANSFER',
199+
'EVM_MOVE_TOKENS',
200+
],
183201
};

0 commit comments

Comments
 (0)