@@ -19,7 +19,7 @@ import {
1919import { useWallet } from "@/components/wallet-provider" ;
2020import { useAutosave } from "@/hooks/use-autosave" ;
2121import { useAppTranslation } from "@/i18n/provider" ;
22- import { TriggerConditionBuilder } from "@/components/trigger-condition-builder" ;
22+ import { TriggerConditionBuilder , type ConditionRule , type Operator } from "@/components/trigger-condition-builder" ;
2323import { PremiumEstimate , type PremiumBreakdown } from "@/components/premium-estimate" ;
2424import { ValidationSummary , type ValidationError } from "@/components/validation-summary" ;
2525import { signTransaction } from "@stellar/freighter-api" ;
@@ -58,6 +58,22 @@ const INITIAL_DRAFT: PolicyDraft = {
5858
5959
6060
61+ function parseConditionString ( condition : string ) : ConditionRule [ ] | undefined {
62+ if ( ! condition || condition . trim ( ) === "" ) return undefined ;
63+ const parts = condition . split ( " AND " ) . map ( ( p ) => p . trim ( ) ) . filter ( Boolean ) ;
64+ if ( parts . length === 0 ) return undefined ;
65+ const rules : ConditionRule [ ] = [ ] ;
66+ const pattern = / ^ ( \w + ) \s * ( > = | < = | > | < | = ) \s * ( .+ ) $ / ;
67+ for ( const part of parts ) {
68+ const match = part . match ( pattern ) ;
69+ if ( ! match ) return undefined ;
70+ const operator = match [ 2 ] as Operator ;
71+ if ( ! [ ">" , "<" , "=" , ">=" , "<=" ] . includes ( operator ) ) return undefined ;
72+ rules . push ( { field : match [ 1 ] , operator, value : match [ 3 ] . trim ( ) } ) ;
73+ }
74+ return rules . length > 0 ? rules : undefined ;
75+ }
76+
6177const MAX_COVERAGE_AMOUNT = 1_000_000 ;
6278
6379const ORACLE_PROVIDER_MAP : Record < PolicyType , OracleProvider [ ] > = {
@@ -523,6 +539,11 @@ export default function CreatePolicyPageClient() {
523539 oracleState === "ready" &&
524540 draft . oracleProvider . trim ( ) !== "" ;
525541
542+ const triggerInitialRules = useMemo (
543+ ( ) => parseConditionString ( draft . triggerCondition ) ,
544+ [ draft . triggerCondition ] ,
545+ ) ;
546+
526547 const isWalletReady = isConnected && walletStatus !== "checking" && walletStatus !== "connecting" ;
527548
528549 return (
@@ -624,6 +645,7 @@ export default function CreatePolicyPageClient() {
624645 < div className = "field field--full" id = "trigger-input" >
625646 < span className = "field__label" > { t ( "createPolicy.configSection.triggerLabel" ) } </ span >
626647 < TriggerConditionBuilder
648+ initialRules = { triggerInitialRules }
627649 onChange = { ( val ) => updateDraft ( "triggerCondition" , val ) }
628650 />
629651 < span className = "field__hint" >
0 commit comments