Skip to content

Commit e58d926

Browse files
committed
feat: add request timeout configuration and update default timeout value in NodeArweaveWallet
1 parent 896bc27 commit e58d926

File tree

4 files changed

+52
-9
lines changed

4 files changed

+52
-9
lines changed

README.md

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ Creates a new wallet instance.
6666

6767
```typescript
6868
const wallet = new NodeArweaveWallet({
69-
port: 3737, // Optional: port number (default: 3737, use 0 for random)
69+
port: 3737, // Optional: port number (default: 3737, use 0 for random)
70+
freePort: false, // Optional: auto-free port if in use (default: false)
71+
requestTimeout: 300000, // Optional: request timeout in ms (default: 5 minutes)
7072
})
7173
```
7274

@@ -412,6 +414,34 @@ If your desired port is already in use, you can enable automatic port freeing to
412414
const wallet = new NodeArweaveWallet({ freePort: true })
413415
```
414416

417+
### Request Timeout Configuration
418+
419+
You can configure how long the wallet will wait for user responses before timing out. This is useful if you need more time to review transactions or if you want faster failures:
420+
421+
```typescript
422+
// Default timeout (5 minutes = 300000ms)
423+
const wallet = new NodeArweaveWallet()
424+
425+
// Custom timeout (10 minutes)
426+
const wallet = new NodeArweaveWallet({
427+
requestTimeout: 600000 // 10 minutes in milliseconds
428+
})
429+
430+
// Shorter timeout (1 minute) for faster failures
431+
const wallet = new NodeArweaveWallet({
432+
requestTimeout: 60000 // 1 minute in milliseconds
433+
})
434+
435+
// All options together
436+
const wallet = new NodeArweaveWallet({
437+
port: 3737,
438+
freePort: true,
439+
requestTimeout: 300000, // 5 minutes
440+
})
441+
```
442+
443+
**Note:** The timeout applies to individual wallet operations (signing, encrypting, etc.). If the user doesn't respond within this time, the operation will fail with a timeout error.
444+
415445
## 💡 Usage Examples
416446

417447
### CLI Tool Example
@@ -604,9 +634,17 @@ The URL will be printed to the console. Open it manually:
604634
http://localhost:3737
605635
```
606636

607-
### Connection Timeout
637+
### Request Timeout
638+
639+
Keep the browser tab open while signing transactions. The package has a default 5-minute timeout for each wallet operation (configurable via `requestTimeout` option). If you need more time to review transactions, increase the timeout:
640+
641+
```typescript
642+
const wallet = new NodeArweaveWallet({
643+
requestTimeout: 600000 // 10 minutes
644+
})
645+
```
608646

609-
Keep the browser tab open while signing transactions. The package has a generous 5-minute timeout, but closing the tab will interrupt operations.
647+
**Note:** Closing the browser tab will immediately interrupt operations regardless of the timeout setting.
610648

611649
## 📄 License
612650

src/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Arweave from 'arweave'
22

33
export const DEFAULT_PORT = 3737
44
export const DEFAULT_HOST = '127.0.0.1'
5-
export const REQUEST_TIMEOUT = 120000 // 120 seconds
5+
export const DEFAULT_REQUEST_TIMEOUT = 300000 // 5 minutes
66
export const BROWSER_TIMEOUT = 30000 // 30 seconds
77
export const SHUTDOWN_DELAY = 500 // 500ms
88
export const BROWSER_READY_DELAY = 500 // 500ms

src/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import {
3434
BROWSER_TIMEOUT,
3535
DEFAULT_HOST,
3636
DEFAULT_PORT,
37-
REQUEST_TIMEOUT,
37+
DEFAULT_REQUEST_TIMEOUT,
3838
SHUTDOWN_DELAY,
3939
} from './constants'
4040
import { base64ToBuffer, bufferToBase64 } from './utils'
@@ -64,6 +64,7 @@ export class NodeArweaveWallet {
6464
this.config = {
6565
port: config.port ?? DEFAULT_PORT,
6666
freePort: config.freePort ?? false,
67+
requestTimeout: config.requestTimeout ?? DEFAULT_REQUEST_TIMEOUT,
6768
}
6869
}
6970

@@ -932,8 +933,8 @@ export class NodeArweaveWallet {
932933
return new Promise((resolve, reject) => {
933934
const timeout = setTimeout(() => {
934935
this.pendingRequests.delete(id)
935-
reject(new Error(`Timeout waiting for ${type}`))
936-
}, REQUEST_TIMEOUT)
936+
reject(new Error(`Timeout waiting for ${type} after ${this.config.requestTimeout! / 1000} seconds`))
937+
}, this.config.requestTimeout!)
937938

938939
this.pendingRequests.set(id, {
939940
resolve: (value: T) => {

src/types.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ export interface ActiveTier {
130130
}
131131

132132
export interface NodeArweaveWalletConfig {
133-
port?: number // Port to listen on (default: 3737, use 0 for random)
134-
freePort?: boolean // Automatically free port if it's already in use (default: false)
133+
/** Port to listen on (default: 3737, use 0 for random) */
134+
port?: number
135+
/** Automatically free port if it's already in use (default: false) */
136+
freePort?: boolean
137+
/** Timeout for wallet requests in milliseconds (default: 300000 = 5 minutes) */
138+
requestTimeout?: number
135139
}

0 commit comments

Comments
 (0)