Skip to content

Commit

Permalink
chore: route -> prepare (#99)
Browse files Browse the repository at this point in the history
* chore: route -> prepare

* chore: correct if statement

* chore: fix target branch

* chore: add permission

* chore: fix ref

* chore: checkout PR branch

* chore: fix CI, switch to PAC

* chore: use PAT correctly?

* chore: update Flutter bindings

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
chris13524 and github-actions[bot] authored Dec 17, 2024
1 parent befa0cb commit 6487f34
Show file tree
Hide file tree
Showing 14 changed files with 197 additions and 198 deletions.
25 changes: 22 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
branches:
- main

permissions:
contents: write # Needed for Flutter CI which auto-updates bindings

env:
CARGO_TERM_COLOR: always

Expand Down Expand Up @@ -155,11 +158,15 @@ jobs:
flutter:
runs-on: macos-latest-xlarge

if: github.event_name == 'pull_request'
steps:
# Checkout repository
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
# Need to use a PAT, not GITHUB_TOKEN, or else CI won't run like normal
token: ${{ secrets.RELEASE_TOKEN_V3 }}

# Cache Flutter dependencies
- name: Cache Flutter dependencies
Expand Down Expand Up @@ -233,4 +240,16 @@ jobs:
flutter_rust_bridge_codegen generate --config-file flutter_rust_bridge.yaml
- run: git diff crates/yttrium_dart
- run: if [ -n "$(git diff crates/yttrium_dart)" ]; then exit 1; fi
# - run: if [ -n "$(git diff crates/yttrium_dart)" ]; then exit 1; fi

- name: Commit and push updated Flutter bindings, if necessary
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add crates/yttrium_dart
if git diff --cached --quiet crates/yttrium_dart; then
echo "No changes to commit."
else
git commit -m "chore: update Flutter bindings"
git push origin HEAD:${{ github.head_ref }}
fi
16 changes: 8 additions & 8 deletions crates/kotlin-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ use {
account_client::{AccountClient as YAccountClient, SignerType},
chain_abstraction::{
api::{
route::{RouteResponse, RouteResponseAvailable},
prepare::{PrepareResponse, RouteResponseAvailable},
status::{StatusResponse, StatusResponseCompleted},
InitialTransaction,
},
client::Client,
currency::Currency,
route_ui_fields::RouteUiFields,
ui_fields::UiFields,
},
config::Config,
private_key_service::PrivateKeyService,
Expand Down Expand Up @@ -142,23 +142,23 @@ impl ChainAbstractionClient {
Self { project_id, client }
}

pub async fn route(
pub async fn prepare(
&self,
initial_transaction: InitialTransaction,
) -> Result<RouteResponse, FFIError> {
) -> Result<PrepareResponse, FFIError> {
self.client
.route(initial_transaction)
.prepare(initial_transaction)
.await
.map_err(|e| FFIError::General(e.to_string()))
}

pub async fn get_route_ui_fields(
pub async fn get_ui_fields(
&self,
route_response: RouteResponseAvailable,
currency: Currency,
) -> Result<RouteUiFields, FFIError> {
) -> Result<UiFields, FFIError> {
self.client
.get_route_ui_fields(route_response, currency)
.get_ui_fields(route_response, currency)
.await
.map(Into::into)
.map_err(|e| FFIError::General(e.to_string()))
Expand Down
2 changes: 1 addition & 1 deletion crates/yttrium/src/chain_abstraction/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use {
};

pub mod fungible_price;
pub mod route;
pub mod prepare;
pub mod status;

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct RouteQueryParams {
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct RouteRequest {
pub struct PrepareRequest {
pub transaction: InitialTransaction,
}

Expand Down Expand Up @@ -148,12 +148,12 @@ pub enum BridgingError {
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "uniffi", derive(uniffi_macros::Enum))]
#[serde(untagged)]
pub enum RouteResponse {
pub enum PrepareResponse {
Success(RouteResponseSuccess),
Error(RouteResponseError),
}

impl RouteResponse {
impl PrepareResponse {
pub fn into_result(
self,
) -> Result<RouteResponseSuccess, RouteResponseError> {
Expand Down
21 changes: 10 additions & 11 deletions crates/yttrium/src/chain_abstraction/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use {
PriceRequestBody, PriceResponseBody,
FUNGIBLE_PRICE_ENDPOINT_PATH, NATIVE_TOKEN_ADDRESS,
},
route::{
RouteQueryParams, RouteRequest, RouteResponse,
prepare::{
PrepareRequest, PrepareResponse, RouteQueryParams,
RouteResponseAvailable, ROUTE_ENDPOINT_PATH,
},
status::{
Expand All @@ -17,12 +17,11 @@ use {
},
currency::Currency,
error::{RouteError, WaitForSuccessError},
route_ui_fields::RouteUiFields,
ui_fields::UiFields,
},
crate::{
chain_abstraction::{
error::RouteUiFieldsError, l1_data_fee::get_l1_data_fee,
route_ui_fields,
error::RouteUiFieldsError, l1_data_fee::get_l1_data_fee, ui_fields,
},
erc20::ERC20,
},
Expand Down Expand Up @@ -63,14 +62,14 @@ impl Client {
}
}

pub async fn route(
pub async fn prepare(
&self,
transaction: InitialTransaction,
) -> Result<RouteResponse, RouteError> {
) -> Result<PrepareResponse, RouteError> {
let response = self
.client
.post(self.base_url.join(ROUTE_ENDPOINT_PATH).unwrap())
.json(&RouteRequest { transaction })
.json(&PrepareRequest { transaction })
.query(&RouteQueryParams { project_id: self.project_id.clone() })
.send()
.await
Expand All @@ -86,13 +85,13 @@ impl Client {
}
}

pub async fn get_route_ui_fields(
pub async fn get_ui_fields(
&self,
route_response: RouteResponseAvailable,
local_currency: Currency,
// TODO use this to e.g. modify priority fee
// _speed: String,
) -> Result<RouteUiFields, RouteUiFieldsError> {
) -> Result<UiFields, RouteUiFieldsError> {
if local_currency != Currency::Usd {
unimplemented!("Only USD currency is supported for now");
}
Expand Down Expand Up @@ -245,7 +244,7 @@ impl Client {
initial_l1_data_fee,
);

Ok(route_ui_fields::get_route_ui_fields(
Ok(ui_fields::ui_fields(
route_response,
estimated_transactions,
estimated_initial_transaction,
Expand Down
2 changes: 1 addition & 1 deletion crates/yttrium/src/chain_abstraction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub mod currency;
pub mod error;
pub mod l1_data_fee;
pub mod local_fee_acc;
pub mod route_ui_fields;
pub mod ui_fields;

#[cfg(test)]
mod test_helpers;
Expand Down
Loading

0 comments on commit 6487f34

Please sign in to comment.