Skip to content

Feature/connect frontend to backend v1 2#25

Merged
Jaymyong66 merged 8 commits intofeature/backend-v1-2from
feature/connect_frontend_to_backend_v1-2
Apr 3, 2026
Merged

Feature/connect frontend to backend v1 2#25
Jaymyong66 merged 8 commits intofeature/backend-v1-2from
feature/connect_frontend_to_backend_v1-2

Conversation

@Jaymyong66
Copy link
Copy Markdown
Contributor

1. 백엔드 변경 설명

backend/src/oracle/program_accounts.rs — MasterPolicy 파싱 오프셋 버그 수정

문제: parse_master_policy()에서 온체인 MasterPolicy 계정의 oracle_feed: Pubkey 필드(32바이트)를 읽지
않고 건너뛰어, 이후 status, created_at, bump 필드가 32바이트 밀린 위치에서 읽혔습니다.

증상:

  • status: 41 (실제로는 Active = 2)
  • created_at: 2547636083394881254 (실제로는 1774793830)
  • status_label: "Unknown"

원인: 온체인 state.rs의 MasterPolicy 구조체에 oracle_feed: Pubkey 필드가 participants 뒤, status 앞에
있는데, program_accounts.rs의 파서가 이 필드를 누락했습니다.

// state.rs (온체인)
pub struct MasterPolicy {
...
pub participants: Vec,
pub oracle_feed: Pubkey, // ← 이 필드가 파서에 없었음
pub status: u8,
pub created_at: i64,
pub bump: u8,
}

수정: MasterPolicyInfo 구조체에 oracle_feed: String 추가, parse_master_policy()에서 read_pubkey() 호출
추가.


backend/src/api.rs — CORS 설정 추가

문제: 프론트엔드(localhost:5173)에서 백엔드(localhost:3000)로의 fetch/EventSource 요청이 CORS 정책에
의해 차단되었습니다.

증상: 브라우저 네트워크 탭에서 flight-policies, events 요청이 CORS error로 실패.

수정: tower-http의 CorsLayer를 라우터에 추가. Cargo.toml에 이미 tower-http = { features = ["cors"] }가
있었으나 사용되지 않고 있었습니다.

let cors = CorsLayer::new()
.allow_origin(Any)
.allow_methods(Any)
.allow_headers(Any);

let app = router::build_router(state).layer(cors);

▎ 참고: 프로덕션에서는 allow_origin(Any) 대신 특정 도메인으로 제한해야 합니다.


2. 프론트엔드 변경사항

Summary

  • 백엔드 API 응답 타입과 프론트엔드 인터페이스 간 불일치 수정 (bump 필드 제거, status_label 추가)
  • useMyPolicies 훅을 직접 Solana RPC에서 백엔드 REST API(GET /api/master-policies)로 전환
  • MasterPolicySummary 타입에 statusLabel 필드 추가하여 백엔드의 status_label 활용
  • Track B → 백엔드 SSE 전환 로드맵 문서 및 테스트/배포 가이드 추가

Changes

타입 수정

  • useMasterPolicyAccount.ts: BackendMasterPolicy에서 bump 제거 → status_label 추가, 변환 시
    bump: 0 하드코딩
  • useFlightPolicies.ts: BackendFlightPolicy에서 bump 제거 → status_label 추가, 변환 시 bump: 0
    하드코딩
  • useMasterPolicies.ts: BackendMasterPolicyItemstatus_label 추가
  • useProtocolStore.ts: MasterPolicySummarystatusLabel 필드 추가

useMyPolicies 리팩터링

  • 직접 Solana RPC (prog.account.masterPolicy.all() + memcmp 필터) → GET /api/master-policies 백엔드
    API
  • leader/reinsurer/participant 역할 감지를 백엔드 응답의 문자열 비교로 변경
  • Track B (레거시 Policy)는 직접 RPC 유지 (백엔드에 해당 API 없음)

문서

  • docs/TRACK_B_SSE_MIGRATION_ROADMAP.md: 레거시 Policy 훅 현황 및 향후 전환 참고
  • docs/TESTING_AND_DEPLOYMENT_GUIDE.md: 로컬 테스트 시나리오 8개 + Docker 배포 가이드

Test plan

  • npx tsc --noEmit 타입 체크 통과 확인
  • 백엔드 실행 후 curl /api/master-policies에서 status_label, oracle_feed 정상 반환 확인
  • 프론트엔드 onchain 모드에서 Master Policy 선택 시 데이터 정상 표시
  • Portal 페이지에서 useMyPolicies가 백엔드 API 경유로 정책 목록 표시
  • SSE 이벤트 스트림 연결 및 실시간 업데이트 동작 확인

@Jaymyong66 Jaymyong66 self-assigned this Apr 1, 2026
@Jaymyong66 Jaymyong66 merged commit 9d8c590 into feature/backend-v1-2 Apr 3, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants