Feat/public fee estimation#6
Conversation
Adds a public, read-only provider method so dApps can query the
required network fee for a simple send without duplicating wallet/WASM
transaction-building logic:
- PROVIDER_METHODS.ESTIMATE_TRANSACTION_FEE ('nock_estimateTransactionFee')
- EstimateTransactionFeeRequest / EstimateTransactionFeeResponse types
- NockchainProvider.estimateTransactionFee({ to, amount }) -> { fee }
(fee in nicks, canonical string)
Also documents the optional-fee semantics on SendTransactionRequest:
when fee is omitted the wallet estimates it for the approval popup,
auto-calculates the exact fee at build time, and reports the actual
fee used in the response.
The method is API 1-only; compat v0 mapping passes it through untouched
(default case), which is intentional.
Greptile SummaryThis PR adds a public
Confidence Score: 4/5The change is a straightforward, additive feature with no modifications to existing logic; safe to merge. The new method follows the same connect-guard → RPC-dispatch pattern as every other provider method and introduces no shared mutable state. The only thing worth a second look is a minor documentation inconsistency in the src/types.ts — the EstimateTransactionFeeRequest.amount JSDoc comment should match the more descriptive wording used on the same field in SendTransactionRequest.
|
| Filename | Overview |
|---|---|
| src/provider.ts | Adds estimateTransactionFee method following the same guard-and-request pattern as sendTransaction and signTx; well-documented with JSDoc |
| src/types.ts | Adds EstimateTransactionFeeRequest and EstimateTransactionFeeResponse interfaces; EstimateTransactionFeeRequest.amount comment is less descriptive than the parallel field in SendTransactionRequest |
| src/constants.ts | Adds ESTIMATE_TRANSACTION_FEE constant to PROVIDER_METHODS; clean addition consistent with existing constants |
| package.json | Version bump from 0.2.0 to 0.3.0 — appropriate for a new public API addition |
Sequence Diagram
sequenceDiagram
participant dApp
participant NockchainProvider
participant InjectedNockchain as window.nockchain
dApp->>NockchainProvider: "estimateTransactionFee({ to, amount })"
alt not connected
NockchainProvider-->>dApp: throw NoAccountError
else connected
NockchainProvider->>InjectedNockchain: "request({ method: 'nock_estimateTransactionFee', params, api: '1.0.0' })"
alt wallet locked / no UTXOs / API 0 wallet
InjectedNockchain-->>NockchainProvider: RPC error
NockchainProvider-->>dApp: throw RpcError
else success
InjectedNockchain-->>NockchainProvider: "EstimateTransactionFeeResponse { fee }"
NockchainProvider-->>dApp: "EstimateTransactionFeeResponse { fee }"
end
end
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
src/types.ts:95-100
The `amount` field on `EstimateTransactionFeeRequest` omits the accepted-type note that appears on the parallel field in `SendTransactionRequest`. Since both fields carry the same `Nicks` type and the same runtime coercion rules apply, users consulting one interface but not the other may not know that legacy numbers and bigints are also accepted.
```suggestion
export interface EstimateTransactionFeeRequest {
/** Recipient address (base58-encoded public key hash / PKH) */
to: Address;
/** Amount to send in nicks (legacy number + canonical string/bigint accepted) */
amount: Nicks;
}
```
Reviews (1): Last reviewed commit: "chore: bump version to 0.3.0" | Re-trigger Greptile
Mirror the type-coercion note from SendTransactionRequest.amount so the two parallel interfaces document the same accepted runtime types (legacy number + canonical string/bigint). Addresses review feedback on PR #6.
No description provided.