Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions resources/gaming-fe/src/constants/wallet-connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 4 additions & 0 deletions resources/gaming-fe/src/hooks/BlockchainConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export interface BlockchainOutboundTransactionRequest {

export type BlockchainOutboundAddressRequest = boolean;

export type BlockchainOutboundFeeRequest = boolean;

export type BlockchainOutboundBalanceRequest = boolean;

export interface BlockchainOutboundRequest {
Expand All @@ -26,6 +28,7 @@ export interface BlockchainOutboundRequest {
transaction?: BlockchainOutboundTransactionRequest;
getAddress?: BlockchainOutboundAddressRequest;
getBalance?: BlockchainOutboundBalanceRequest;
getFee?: BlockchainOutboundFeeRequest;
}

export interface BlockchainInboundReply {
Expand All @@ -34,6 +37,7 @@ export interface BlockchainInboundReply {
transaction?: string;
getAddress?: BlockchainInboundAddressResult;
getBalance?: number;
getFee?: number;
error?: string;
}

Expand Down
9 changes: 9 additions & 0 deletions resources/gaming-fe/src/hooks/FakeBlockchainInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ export class FakeBlockchainInterface implements InternalBlockchainInterface {
getBalance(): Promise<number> {
return this.upstream.getBalance();
}

getFeeEstimate(): Promise<number> {
return this.upstream.getFeeEstimate();
}
}

export const fakeBlockchainInfo = new FakeBlockchainInterface(
Expand All @@ -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(
Expand Down Expand Up @@ -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({
Expand Down
9 changes: 9 additions & 0 deletions resources/gaming-fe/src/hooks/JsonRpcContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
GetCurrentAddressRequest,
GetCurrentAddressResponse,
} from '../types/rpc/GetCurrentAddress';
import { GetFeeEstimateRequest, GetFeeEstimateResponse } from '../types/rpc/GetFeeEstimate';
import {
GetNextAddressRequest,
GetNextAddressResponse,
Expand Down Expand Up @@ -320,6 +321,13 @@ async function getWalletAddresses(data: GetWalletAddressesRequest) {
);
}

async function getFeeEstimate(data: GetFeeEstimateRequest) {
return await request<GetFeeEstimateResponse>(
ChiaMethod.GetFeeEstimate,
data,
);
}

// Offers

async function getAllOffers(data: GetAllOffersRequest) {
Expand Down Expand Up @@ -454,6 +462,7 @@ export const rpc = {
getNextAddress,
getSyncStatus,
getWalletAddresses,
getFeeEstimate,

// Offers
getAllOffers,
Expand Down
31 changes: 20 additions & 11 deletions resources/gaming-fe/src/hooks/RealBlockchainInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions resources/gaming-fe/src/types/ChiaGaming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,16 @@ export class ExternalBlockchainInterface {
},
).then((f) => f.json());
}

getFeeEstimate(): Promise<number> {
return fetch(
`${this.baseUrl}/get_fee_estimate?user=${this.token}`,
{
body: '',
method: 'POST'
},
).then((f) => f.json());
}
}

function select_cards_using_bits<T>(card: T[], mask: number): T[][] {
Expand Down
4 changes: 4 additions & 0 deletions resources/gaming-fe/src/types/rpc/GetFeeEstimate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface GetFeeEstimateRequest {
}

export type GetFeeEstimateResponse = number;
Loading