@@ -63,12 +63,69 @@ const Schema = Joi.object<V2RouteResponse>({
6363 signer_address : Joi . string ( ) . required ( ) ,
6464 msgs : Joi . array ( )
6565 . items (
66- Joi . object ( {
67- type : Joi . string ( ) . required ( ) ,
68- value : Joi . any ( ) . required ( ) ,
66+ Joi . alternatives ( ) . conditional ( Joi . ref ( ".type" ) , {
67+ switch : [
68+ {
69+ is : "cosmos-sdk/MsgTransfer" ,
70+ then : Joi . object ( {
71+ type : Joi . string ( )
72+ . valid ( "cosmos-sdk/MsgTransfer" )
73+ . required ( ) ,
74+ source_port : Joi . string ( ) . required ( ) ,
75+ source_channel : Joi . string ( ) . required ( ) ,
76+ token : Joi . array ( )
77+ . items (
78+ Joi . object ( {
79+ denom : Joi . string ( ) . required ( ) ,
80+ amount : Joi . string ( ) . required ( ) ,
81+ } )
82+ )
83+ . required ( ) ,
84+ sender : Joi . string ( ) . required ( ) ,
85+ receiver : Joi . string ( ) . required ( ) ,
86+ timeout_timestamp : Joi . string ( ) . required ( ) ,
87+ memo : Joi . string ( ) . optional ( ) ,
88+ } ) . unknown ( true ) ,
89+ } ,
90+ {
91+ is : "wasm/MsgExecuteContract" ,
92+ then : Joi . object ( {
93+ type : Joi . string ( )
94+ . valid ( "wasm/MsgExecuteContract" )
95+ . required ( ) ,
96+ sender : Joi . string ( ) . required ( ) ,
97+ contract : Joi . string ( ) . required ( ) ,
98+ msg : Joi . object ( ) . required ( ) ,
99+ funds : Joi . array ( )
100+ . items (
101+ Joi . object ( {
102+ denom : Joi . string ( ) . required ( ) ,
103+ amount : Joi . string ( ) . required ( ) ,
104+ } )
105+ )
106+ . required ( ) ,
107+ } ) . unknown ( true ) ,
108+ } ,
109+ {
110+ is : "cctp/DepositForBurn" ,
111+ then : Joi . object ( {
112+ type : Joi . string ( )
113+ . valid ( "cctp/DepositForBurn" )
114+ . required ( ) ,
115+ from : Joi . string ( ) . required ( ) ,
116+ amount : Joi . string ( ) . required ( ) ,
117+ destination_domain : Joi . number ( ) . required ( ) ,
118+ mint_recipient : Joi . string ( ) . required ( ) ,
119+ burn_token : Joi . string ( ) . required ( ) ,
120+ } ) . unknown ( true ) ,
121+ } ,
122+ ] ,
123+ otherwise : Joi . object ( {
124+ type : Joi . string ( ) . required ( ) ,
125+ } ) . unknown ( true ) ,
69126 } )
70127 )
71- . required ( ) , // TODO: add schema for msgs
128+ . required ( ) ,
72129 } )
73130 . unknown ( true )
74131 . required ( ) ,
@@ -147,90 +204,49 @@ export class ObservableQueryRouteV2Inner extends ObservableQuery<V2RouteResponse
147204 ) ;
148205 }
149206
150- // NOTE: 브릿지 수수료, tx 수수료 구분이 안되어 있어서 백엔드 쪽에서 확인하고 처리해야 함
151-
152- // 프로퍼티 이름이 애매하긴 한데... 일단 skip response에서 estimated_fees를 차리하기 위한 property이고
153- // 현재 이 값은 브릿징 수수료를 의미한다.
154- // @computed
155- // get otherFees(): CoinPretty[] {
156- // if (!this.response) {
157- // return [];
158- // }
159- // if (!this.response.data.fees) {
160- // return [];
161- // }
162-
163- // // return this.response.data.fees.map((fee) => {
164- // // return new CoinPretty(
165- // // this.chainGetter.hasChain(fee.origin_asset.chain_id)
166- // // ? this.chainGetter
167- // // .getChain(fee.origin_asset.chain_id)
168- // // .forceFindCurrency(fee.origin_asset.denom)
169- // // : this.chainGetter
170- // // .getChain(`eip155:${fee.origin_asset.chain_id}`)
171- // // .forceFindCurrency(
172- // // (() => {
173- // // if (fee.origin_asset.denom.startsWith("0x")) {
174- // // return `erc20:${fee.origin_asset.denom.toLowerCase()}`;
175- // // }
176-
177- // // return fee.origin_asset.denom;
178- // // })()
179- // // ),
180- // // fee.amount
181- // // );
182- // // });
183-
184- // return [];
185- // }
186-
187- // @computed
188- // get swapFee(): CoinPretty[] {
189- // if (!this.response) {
190- // return [
191- // new CoinPretty(
192- // this.chainGetter
193- // .getChain(this.toChainId)
194- // .forceFindCurrency(this.toDenom),
195- // "0"
196- // ),
197- // ];
198- // }
199-
200- // const estimatedAffiliateFees: {
201- // fee: string;
202- // venueChainId: string;
203- // }[] = [];
204-
205- // for (const operation of this.response.data.operations) {
206- // if ("swap" in operation) {
207- // const swapIn = operation.swap.swap_in ?? operation.swap.smart_swap_in;
208- // if (swapIn) {
209- // estimatedAffiliateFees.push({
210- // fee: operation.swap.estimated_affiliate_fee,
211- // // QUESTION: swap_out이 생기면...?
212- // venueChainId: swapIn.swap_venue.chain_id,
213- // });
214- // }
215- // }
216- // }
207+ @computed
208+ get bridgeFees ( ) : CoinPretty [ ] {
209+ if ( ! this . response ) {
210+ return [ ] ;
211+ }
212+ if ( ! this . response . data . fees || this . response . data . fees . length === 0 ) {
213+ return [ ] ;
214+ }
217215
218- // return estimatedAffiliateFees.map(({ fee, venueChainId }) => {
219- // const split = fee.split(/^([0-9]+)(\s)*([a-zA-Z][a-zA-Z0-9/-]*)$/);
216+ const fees = this . response . data . fees ;
220217
221- // if (split.length !== 5) {
222- // throw new Error(`Invalid fee format: ${fee}`);
223- // }
218+ // 동일한 denom의 fee가 있으면 합치기
219+ // CHECK: usd amount랑 이미지랑 다 주는데 그냥 원본값 반환하기 or 가공해서 반환하기
220+ const feeMap = new Map < string , CoinPretty > ( ) ;
221+ for ( const fee of fees ) {
222+ const coinPretty = new CoinPretty (
223+ this . chainGetter . hasChain ( fee . fee_token . chain_id )
224+ ? this . chainGetter
225+ . getChain ( fee . fee_token . chain_id )
226+ . forceFindCurrency ( fee . fee_token . denom )
227+ : this . chainGetter
228+ . getChain ( `eip155:${ fee . fee_token . chain_id } ` )
229+ . forceFindCurrency (
230+ ( ( ) => {
231+ if ( fee . fee_token . denom . startsWith ( "0x" ) ) {
232+ return `erc20:${ fee . fee_token . denom . toLowerCase ( ) } ` ;
233+ }
234+ return fee . fee_token . denom ;
235+ } ) ( )
236+ ) ,
237+ fee . amount
238+ ) ;
224239
225- // const amount = split[1];
226- // const denom = split[3];
240+ const denom = fee . fee_token . denom ;
241+ if ( feeMap . has ( denom ) ) {
242+ feeMap . get ( denom ) ! . add ( coinPretty ) ;
243+ } else {
244+ feeMap . set ( denom , coinPretty ) ;
245+ }
246+ }
227247
228- // return new CoinPretty(
229- // this.chainGetter.getChain(venueChainId).forceFindCurrency(denom),
230- // amount
231- // );
232- // });
233- // }
248+ return Array . from ( feeMap . values ( ) ) ;
249+ }
234250
235251 @computed
236252 get transactions ( ) : RouteTransaction [ ] {
0 commit comments