Skip to content

Commit

Permalink
feat: add proper dapp url
Browse files Browse the repository at this point in the history
  • Loading branch information
Rakowskiii committed Jul 28, 2023
1 parent e004af0 commit fc3b84f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 16 deletions.
26 changes: 14 additions & 12 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,13 @@ jobs:
with:
environment: "STAGING"

validate-staging-swift:
needs: deploy-infra-staging
uses: ./.github/workflows/validate_swift.yml
with:
notify-endpoint: 'staging.notify.walletconnect.com'
relay-endpoint: 'staging.relay.walletconnect.com'
# TODO: Restore once swift is ready for notify
# validate-staging-swift:
# needs: deploy-infra-staging
# uses: ./.github/workflows/validate_swift.yml
# with:
# notify-endpoint: 'staging.notify.walletconnect.com'
# relay-endpoint: 'staging.relay.walletconnect.com'


##############################################################################
Expand All @@ -103,10 +104,11 @@ jobs:
environment: "PROD"


validate-swift-prod:
needs: [deploy-infra-prod]
uses: ./.github/workflows/validate_swift.yml
with:
notify-endpoint: 'notify.walletconnect.com'
relay-endpoint: 'relay.walletconnect.com'
# TODO: Restore once swift is ready for notify
# validate-swift-prod:
# needs: [deploy-infra-prod]
# uses: ./.github/workflows/validate_swift.yml
# with:
# notify-endpoint: 'notify.walletconnect.com'
# relay-endpoint: 'relay.walletconnect.com'

21 changes: 19 additions & 2 deletions src/handlers/subscribe_topic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,16 @@ pub struct Keypair {
pub public_key: String,
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct SubscribeTopicData {
dapp_url: String,
}

pub async fn handler(
State(state): State<Arc<AppState>>,
AuthedProjectId(project_id, _): AuthedProjectId,
Json(subscribe_topic_data): Json<SubscribeTopicData>,
) -> Result<axum::response::Response, crate::error::Error> {
info!("Generating keypair for project: {}", project_id);
let db = state.database.clone();
Expand All @@ -48,6 +55,17 @@ pub async fn handler(
project_data, signing_pubkey, identity_pubkey
);

if project_data.dapp_url != subscribe_topic_data.dapp_url {
info!("Updating dapp_url for project: {}", project_id);
db.collection::<ProjectData>("project_data")
.update_one(
doc! { "_id": project_id.clone()},
doc! { "$set": { "dapp_url": &subscribe_topic_data.dapp_url } },
None,
)
.await?;
}

return Ok(Json(
json!({ "identityPublicKey": identity_pubkey, "subscribeTopicPublicKey": signing_pubkey}),
)
Expand All @@ -74,8 +92,7 @@ pub async fn handler(
private_key: hex::encode(identity_secret.to_bytes()),
public_key: identity_public.clone(),
},
// TODO: Proper dapp url
dapp_url: "http://localhost:3000".into(),
dapp_url: subscribe_topic_data.dapp_url,
topic: topic.clone(),
};

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pub async fn bootstap(mut shutdown: broadcast::Receiver<()>, config: Configurati
.route("/:project_id/notify", post(handlers::notify::handler))
.route(
"/:project_id/subscribe-topic",
get(handlers::subscribe_topic::handler),
post(handlers::subscribe_topic::handler),
)
.route(
"/:project_id/register-webhook",
Expand Down
3 changes: 2 additions & 1 deletion tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ PROJECT_ID to be set",

// Register project - generating subscribe topic
let dapp_pubkey_response: serde_json::Value = http_client
.get(format!("{}/{}/subscribe-topic", &notify_url, &project_id))
.post(format!("{}/{}/subscribe-topic", &notify_url, &project_id))
.bearer_auth(&project_secret)
.json(&json!({ "dappUrl": "https://my-test-app.com" }))
.send()
.await
.unwrap()
Expand Down

0 comments on commit fc3b84f

Please sign in to comment.