diff --git a/resources/gaming-fe/src/constants/wallet-connect.ts b/resources/gaming-fe/src/constants/wallet-connect.ts index b7a0ff613..d76c6973a 100644 --- a/resources/gaming-fe/src/constants/wallet-connect.ts +++ b/resources/gaming-fe/src/constants/wallet-connect.ts @@ -13,6 +13,7 @@ export enum ChiaMethod { SignMessageByAddress = 'chia_signMessageByAddress', VerifySignature = 'chia_verifySignature', GetNextAddress = 'chia_getNextAddress', + GetFeeEstimate = 'chia_getFeeEstimate', GetSyncStatus = 'chia_getSyncStatus', GetAllOffers = 'chia_getAllOffers', GetOffersCount = 'chia_getOffersCount', diff --git a/resources/gaming-fe/src/hooks/BlockchainConnector.ts b/resources/gaming-fe/src/hooks/BlockchainConnector.ts index 10b514217..99f569d5c 100644 --- a/resources/gaming-fe/src/hooks/BlockchainConnector.ts +++ b/resources/gaming-fe/src/hooks/BlockchainConnector.ts @@ -18,6 +18,8 @@ export interface BlockchainOutboundTransactionRequest { export type BlockchainOutboundAddressRequest = boolean; +export type BlockchainOutboundFeeRequest = boolean; + export type BlockchainOutboundBalanceRequest = boolean; export interface BlockchainOutboundRequest { @@ -26,6 +28,7 @@ export interface BlockchainOutboundRequest { transaction?: BlockchainOutboundTransactionRequest; getAddress?: BlockchainOutboundAddressRequest; getBalance?: BlockchainOutboundBalanceRequest; + getFee?: BlockchainOutboundFeeRequest; } export interface BlockchainInboundReply { @@ -34,6 +37,7 @@ export interface BlockchainInboundReply { transaction?: string; getAddress?: BlockchainInboundAddressResult; getBalance?: number; + getFee?: number; error?: string; } diff --git a/resources/gaming-fe/src/hooks/FakeBlockchainInterface.ts b/resources/gaming-fe/src/hooks/FakeBlockchainInterface.ts index da6283dbe..8478101ae 100644 --- a/resources/gaming-fe/src/hooks/FakeBlockchainInterface.ts +++ b/resources/gaming-fe/src/hooks/FakeBlockchainInterface.ts @@ -210,6 +210,10 @@ export class FakeBlockchainInterface implements InternalBlockchainInterface { getBalance(): Promise { return this.upstream.getBalance(); } + + getFeeEstimate(): Promise { + return this.upstream.getFeeEstimate(); + } } export const fakeBlockchainInfo = new FakeBlockchainInterface( @@ -226,6 +230,7 @@ export function connectSimulatorBlockchain() { let transaction = evt.transaction; let getAddress = evt.getAddress; let getBalance = evt.getBalance; + let getFee = evt.getFee; if (initialSpend) { return fakeBlockchainInfo .do_initial_spend( @@ -271,6 +276,10 @@ export function connectSimulatorBlockchain() { fakeBlockchainInfo.getBalance().then((balance) => { blockchainConnector.replyEmitter({ responseId: evt.requestId, getBalance: balance }); }); + } else if (getFee) { + fakeBlockchainInfo.getFeeEstimate().then((fee) => { + blockchainConnector.replyEmitter({ responseId: evt.requestId, getFee: fee }); + }); } else { console.error(`unknown blockchain request type ${JSON.stringify(evt)}`); blockchainConnector.replyEmitter({ diff --git a/resources/gaming-fe/src/hooks/JsonRpcContext.tsx b/resources/gaming-fe/src/hooks/JsonRpcContext.tsx index d2ddfb9e4..888d61fca 100644 --- a/resources/gaming-fe/src/hooks/JsonRpcContext.tsx +++ b/resources/gaming-fe/src/hooks/JsonRpcContext.tsx @@ -39,6 +39,7 @@ import { GetCurrentAddressRequest, GetCurrentAddressResponse, } from '../types/rpc/GetCurrentAddress'; +import { GetFeeEstimateRequest, GetFeeEstimateResponse } from '../types/rpc/GetFeeEstimate'; import { GetNextAddressRequest, GetNextAddressResponse, @@ -320,6 +321,13 @@ async function getWalletAddresses(data: GetWalletAddressesRequest) { ); } +async function getFeeEstimate(data: GetFeeEstimateRequest) { + return await request( + ChiaMethod.GetFeeEstimate, + data, + ); +} + // Offers async function getAllOffers(data: GetAllOffersRequest) { @@ -454,6 +462,7 @@ export const rpc = { getNextAddress, getSyncStatus, getWalletAddresses, + getFeeEstimate, // Offers getAllOffers, diff --git a/resources/gaming-fe/src/hooks/RealBlockchainInterface.ts b/resources/gaming-fe/src/hooks/RealBlockchainInterface.ts index 0b1c3611c..4c79fa076 100644 --- a/resources/gaming-fe/src/hooks/RealBlockchainInterface.ts +++ b/resources/gaming-fe/src/hooks/RealBlockchainInterface.ts @@ -236,6 +236,8 @@ export function connectRealBlockchain(baseUrl: string) { let transaction = evt.transaction; let getAddress = evt.getAddress; let getBalance = evt.getBalance; + let getFee = evt.getFee; + if (initialSpend) { try { const currentAddress = await rpc.getCurrentAddress({ @@ -332,18 +334,25 @@ export function connectRealBlockchain(baseUrl: string) { walletId: 1, }) .then((address) => { - if (address !== lastRecvAddress) { - console.log('walletconnect recv currentAddress:', address); - lastRecvAddress = address; - } - const puzzleHash = toHexString(bech32.decode(address).data as any); - const addressData = { address, puzzleHash }; + if (address !== lastRecvAddress) { + console.log('walletconnect recv currentAddress:', address); + lastRecvAddress = address; + } + const puzzleHash = toHexString(bech32.decode(address).data as any); + const addressData = { address, puzzleHash }; - blockchainConnector.replyEmitter({ - responseId: evt.requestId, - getAddress: addressData - }); - }); + blockchainConnector.replyEmitter({ + responseId: evt.requestId, + getAddress: addressData + }); + }); + } else if (getFee) { + rpc.getFeeEstimate({}).then((feeResult: number) => { + blockchainConnector.replyEmitter({ + responseId: evt.requestId, + getFee: feeResult + }); + }); } else if (getBalance) { rpc.getWalletBalance({ walletId: 1 diff --git a/resources/gaming-fe/src/types/ChiaGaming.ts b/resources/gaming-fe/src/types/ChiaGaming.ts index 63526bc6d..f689ab263 100644 --- a/resources/gaming-fe/src/types/ChiaGaming.ts +++ b/resources/gaming-fe/src/types/ChiaGaming.ts @@ -375,6 +375,16 @@ export class ExternalBlockchainInterface { }, ).then((f) => f.json()); } + + getFeeEstimate(): Promise { + return fetch( + `${this.baseUrl}/get_fee_estimate?user=${this.token}`, + { + body: '', + method: 'POST' + }, + ).then((f) => f.json()); + } } function select_cards_using_bits(card: T[], mask: number): T[][] { diff --git a/resources/gaming-fe/src/types/rpc/GetFeeEstimate.ts b/resources/gaming-fe/src/types/rpc/GetFeeEstimate.ts new file mode 100644 index 000000000..5cd35307e --- /dev/null +++ b/resources/gaming-fe/src/types/rpc/GetFeeEstimate.ts @@ -0,0 +1,4 @@ +export interface GetFeeEstimateRequest { +} + +export type GetFeeEstimateResponse = number;