Skip to content

Commit cb1efdb

Browse files
authored
Fixed all the typing errors and also removed the malformed use of the state (elizaOS#2843)
1 parent 9b8f7c4 commit cb1efdb

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

packages/plugin-sui/src/actions/transfer.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export default {
6363
"SEND_SUI",
6464
"PAY",
6565
],
66-
validate: async (runtime: IAgentRuntime, message: Memory) => {
66+
validate: async (_runtime: IAgentRuntime, message: Memory) => {
6767
console.log("Validating sui transfer from user:", message.userId);
6868
//add custom validate logic here
6969
/*
@@ -98,10 +98,11 @@ export default {
9898
state.walletInfo = walletInfo;
9999

100100
// Initialize or update state
101-
if (!state) {
102-
state = (await runtime.composeState(message)) as State;
101+
let currentState = state;
102+
if (!currentState) {
103+
currentState = (await runtime.composeState(message)) as State;
103104
} else {
104-
state = await runtime.updateRecentMessageState(state);
105+
currentState = await runtime.updateRecentMessageState(currentState);
105106
}
106107

107108
// Define the schema for the expected output
@@ -112,7 +113,7 @@ export default {
112113

113114
// Compose transfer context
114115
const transferContext = composeContext({
115-
state,
116+
state: currentState,
116117
template: transferTemplate,
117118
});
118119

@@ -146,7 +147,7 @@ export default {
146147
});
147148

148149
const adjustedAmount = BigInt(
149-
Number(transferContent.amount) * Math.pow(10, SUI_DECIMALS)
150+
Number(transferContent.amount) * (10 ** SUI_DECIMALS)
150151
);
151152
console.log(
152153
`Transferring: ${transferContent.amount} tokens (${adjustedAmount} base units)`

packages/plugin-sui/src/providers/wallet.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { getFullnodeUrl, SuiClient } from "@mysten/sui/client";
1111
import { MIST_PER_SUI } from "@mysten/sui/utils";
1212
import BigNumber from "bignumber.js";
1313
import NodeCache from "node-cache";
14-
import * as path from "path";
14+
import * as path from "node:path";
1515
import { parseAccount } from "../utils";
1616

1717
// Provider configuration
@@ -106,9 +106,8 @@ export class WalletProvider {
106106
console.error(`Attempt ${i + 1} failed:`, error);
107107
lastError = error;
108108
if (i < PROVIDER_CONFIG.MAX_RETRIES - 1) {
109-
const delay = PROVIDER_CONFIG.RETRY_DELAY * Math.pow(2, i);
109+
const delay = PROVIDER_CONFIG.RETRY_DELAY * (2 ** i); // Replaced Math.pow with **
110110
await new Promise((resolve) => setTimeout(resolve, delay));
111-
continue;
112111
}
113112
}
114113
}

packages/plugin-sui/src/utils.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ const parseAccount = (
99
const privateKey = runtime.getSetting("SUI_PRIVATE_KEY");
1010
if (!privateKey) {
1111
throw new Error("SUI_PRIVATE_KEY is not set");
12-
} else if (privateKey.startsWith("suiprivkey")) {
12+
}
13+
if (privateKey.startsWith("suiprivkey")) {
1314
return loadFromSecretKey(privateKey);
14-
} else {
15-
return loadFromMnemonics(privateKey);
1615
}
16+
return loadFromMnemonics(privateKey);
1717
};
1818

1919
const loadFromSecretKey = (privateKey: string) => {
@@ -22,7 +22,7 @@ const loadFromSecretKey = (privateKey: string) => {
2222
try {
2323
return KeypairClass.fromSecretKey(privateKey);
2424
} catch {
25-
continue;
25+
// Removed unnecessary continue
2626
}
2727
}
2828
throw new Error("Failed to initialize keypair from secret key");
@@ -38,7 +38,7 @@ const loadFromMnemonics = (mnemonics: string) => {
3838
try {
3939
return Class[method](mnemonics);
4040
} catch {
41-
continue;
41+
// Removed unnecessary continue
4242
}
4343
}
4444
throw new Error("Failed to derive keypair from mnemonics");

0 commit comments

Comments
 (0)