/* Ċ Ġ* ĠCopyright Ġ 2 0 2 2 ĠP era ĠWallet , ĠL DA Ċ Ġ* ĠLicensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License "); Ċ Ġ* Ġyou Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ Ġ* ĠYou Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ġhttp :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ġ* ĠUnless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ Ġ* Ġdistributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ Ġ* ĠWITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ Ġ* ĠSee Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ Ġ* Ġ Ġlimitations Ġunder Ġthe ĠLicense Ċ Ġ* Ċ Ġ*/ Ċ Ċ package Ġcom . al gor and . android . utils . validator Ċ Ċ import Ġcom . al gor and . android . R Ċ import Ġcom . al gor and . android . core . Account Manager Ċ import Ġcom . al gor and . android . models . Account Cache Data Ċ import Ġcom . al gor and . android . models . Account Information Ċ import Ġcom . al gor and . android . models . Annotated String Ċ import Ġcom . al gor and . android . models . Asset Information Ċ import Ġcom . al gor and . android . models . Asset Information . Companion . ALG OR AND _ ID Ċ import Ġcom . al gor and . android . models . Result Ċ import Ġcom . al gor and . android . use case . Account Detail UseCase Ċ import Ġcom . al gor and . android . utils . exceptions . Warning Exception Ċ import Ġcom . al gor and . android . utils . isEqualTo Ċ import Ġcom . al gor and . android . utils . is Less er Than Ċ import Ġcom . al gor and . android . utils . isValid Address Ċ import Ġcom . al gor and . android . utils . min Balance Per Asset As BigInteger Ċ import Ġjava . math . BigInteger Ċ import Ġjavax . inject . Inject Ċ Ċ class ĠAccount Transaction Validator Ġ@ Inject Ġconstructor ( ĊĠĠĠ Ġprivate Ġval Ġaccount Manager : ĠAccount Manager , ĊĠĠĠ Ġprivate Ġval Ġaccount Detail UseCase : ĠAccount Detail UseCase , Ċ ) Ġ{ ĊĊĠĠĠ Ġfun Ġis Account Address Valid ( to Account PublicKey : ĠString ): ĠResult < String > Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ( to Account PublicKey . isValid Address ()) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn ĠResult . Success ( to Account PublicKey ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġreturn ĠResult . Error ( Warning Exception ( R . string . warning , ĠAnnot ated String ( R . string . key _ not _ valid ))) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġis Selected Asset Valid ( from Account PublicKey : ĠString , Ġasset Id : ĠLong ): ĠBoolean Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġaccount Detail Ġ= Ġaccount Detail UseCase . get Cached Account Detail ( from Account PublicKey )?. data ĊĠĠĠĠĠĠĠ Ġval Ġis Algo Ġ= Ġasset Id Ġ== ĠAL G OR AND _ ID ĊĠĠĠĠĠĠĠ Ġreturn Ġaccount Detail ?. account Information ?. asset Hold ing List ?. any Ġ{ Ġit . asset Id Ġ== Ġasset Id Ġ} Ġ== Ġtrue Ġ|| Ġis Algo ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġis Selected Asset Supported ( account Information : ĠAccount Information , Ġasset Id : ĠLong ): ĠBoolean Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġaccount Information . is Asset Supported ( asset Id ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġis There Any Account With To PublicKey ( to Account Address : ĠString ): ĠBoolean Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġaccount Manager . is There Any Account With PublicKey ( to Account Address ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġis Sending Amount Less er Than Minimum Balance ( ĊĠĠĠĠĠĠĠ Ġto Account Selected Asset Balance : ĠBigInteger , ĊĠĠĠĠĠĠĠ Ġamount : ĠBigInteger , ĊĠĠĠĠĠĠĠ Ġmin Balance : ĠBigInteger ĊĠĠĠ Ġ): ĠBoolean Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġ( to Account Selected Asset Balance Ġ+ Ġamount ) Ġis Less er Than Ġmin Balance ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġis Close Transaction To Same Account ( ĊĠĠĠĠĠĠĠ Ġfrom Account : ĠAccount Cache Data ?, ĊĠĠĠĠĠĠĠ Ġto Account : ĠString , ĊĠĠĠĠĠĠĠ Ġselected Asset : ĠAsset Information ?, ĊĠĠĠĠĠĠĠ Ġamount : ĠBigInteger ĊĠĠĠ Ġ): ĠBoolean Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġis Max Ġ= Ġamount Ġ== Ġselected Asset ?. amount ĊĠĠĠĠĠĠĠ Ġval Ġhas Only Algo Ġ= Ġfrom Account ?. account Information ?. run Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ! is There An Opt ed In App () Ġ|| Ġ! is There Any Different Asset () ĊĠĠĠĠĠĠĠ Ġ} Ġ?: Ġfalse ĊĠĠĠĠĠĠĠ Ġreturn Ġfrom Account ?. account ?. address Ġ== Ġto Account Ġ&& Ġselected Asset ?. is Algo () Ġ== Ġtrue Ġ&& Ġis Max Ġ&& Ġhas Only Algo ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġis Account New ly Opened And Balance Invalid ( ĊĠĠĠĠĠĠĠ Ġreceiver Account Information : ĠAccount Information , ĊĠĠĠĠĠĠĠ Ġamount : ĠBigInteger , ĊĠĠĠĠĠĠĠ Ġasset Id : ĠLong ĊĠĠĠ Ġ): ĠBoolean Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġasset Id Ġ== ĠAL G OR AND _ ID Ġ&& ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreceiver Account Information . amount Ġis EqualTo ĠBigInteger . ZERO Ġ&& ĊĠĠĠĠĠĠĠĠĠĠĠ Ġamount Ġ< Ġmin Balance Per Asset As BigInteger ĊĠĠĠ Ġ} Ċ } Ċ