@@ -6,7 +6,7 @@ import { Service } from '../services';
66import { ClientTransactionResponse , NetworkEnum , RateToken } from '../types' ;
77import { calculateApprovalAmount } from '../utils/fees' ;
88import { ViemClient } from '../viem' ;
9- import { getProtocolAndPlatformsFees } from './graphql/queries' ;
9+ import { getPaymentsByService , getProtocolAndPlatformsFees } from './graphql/queries' ;
1010
1111export class Escrow {
1212 graphQlClient : GraphQLClient ;
@@ -59,21 +59,21 @@ export class Escrow {
5959 let tx ,
6060 cid = proposal . cid ;
6161
62- const protocolAndPlatformsFeesResponse = await this . graphQlClient . get (
63- getProtocolAndPlatformsFees ( proposal . service . platform . id , proposal . platform . id ) ,
62+ const protocolAndPlatformsFees = await this . getProtocolAndPlatformsFees (
63+ proposal . service . platform . id , proposal . platform . id
6464 ) ;
6565
66- console . log ( 'SDK: fees' , protocolAndPlatformsFeesResponse ) ;
66+ console . log ( 'SDK: fees' , protocolAndPlatformsFees ) ;
6767
68- if ( ! protocolAndPlatformsFeesResponse . data ) {
68+ if ( ! protocolAndPlatformsFees . data ) {
6969 throw Error ( 'Unable to fetch fees' ) ;
7070 }
7171
7272 const approvalAmount = calculateApprovalAmount (
7373 proposal . rateAmount ,
74- protocolAndPlatformsFeesResponse . data . servicePlatform . originServiceFeeRate ,
75- protocolAndPlatformsFeesResponse . data . proposalPlatform . originValidatedProposalFeeRate ,
76- protocolAndPlatformsFeesResponse . data . protocols [ 0 ] . protocolEscrowFeeRate ,
74+ protocolAndPlatformsFees . servicePlatform . originServiceFeeRate ,
75+ protocolAndPlatformsFees . proposalPlatform . originValidatedProposalFeeRate ,
76+ protocolAndPlatformsFees . protocols [ 0 ] . protocolEscrowFeeRate ,
7777 ) ;
7878
7979 console . log ( 'SDK: escrow seeking approval for amount: ' , approvalAmount ) ;
@@ -187,4 +187,24 @@ export class Escrow {
187187
188188 return tx ;
189189 }
190+
191+ public async getProtocolAndPlatformsFees (
192+ originServicePlatformId : string ,
193+ originValidatedProposalPlatformId : string ,
194+ ) : Promise < any > {
195+ const query = getProtocolAndPlatformsFees ( originServicePlatformId , originValidatedProposalPlatformId ) ;
196+
197+ const response = await this . graphQlClient . get ( query ) ;
198+
199+ return response ?. data || null ;
200+ }
201+
202+ public async getByService ( serviceId : string , paymentType ?: string ) : Promise < any > {
203+ const query = getPaymentsByService ( serviceId , paymentType ) ;
204+
205+ const response = await this . graphQlClient . get ( query ) ;
206+
207+ return response ?. data ?. payments || null
208+ }
209+
190210}
0 commit comments