Skip to content

Commit 1bfe9c6

Browse files
authored
feat: adding sv and st query parameters for analytics (#945)
1 parent 26fbdc9 commit 1bfe9c6

15 files changed

+162
-63
lines changed

integration/balance.test.ts

+22-37
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,7 @@ describe('Account balance', () => {
1414

1515
it('fulfilled balance Ethereum address', async () => {
1616
let resp: any = await httpClient.get(
17-
`${baseUrl}/v1/account/${fulfilled_eth_address}/balance?projectId=${projectId}&currency=${currency}`,
18-
{
19-
headers: {
20-
'x-sdk-version': sdk_version,
21-
}
22-
}
17+
`${baseUrl}/v1/account/${fulfilled_eth_address}/balance?projectId=${projectId}&currency=${currency}&sv=${sdk_version}`
2318
)
2419
expect(resp.status).toBe(200)
2520
expect(typeof resp.data.balances).toBe('object')
@@ -40,10 +35,9 @@ describe('Account balance', () => {
4035
}
4136
})
4237

43-
it('fulfilled balance Solana address', async () => {
44-
let chainId = 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp'
38+
it('fulfilled balance Ethereum address (deprecated \'x-sdk-version\')', async () => {
4539
let resp: any = await httpClient.get(
46-
`${baseUrl}/v1/account/${fulfilled_solana_address}/balance?projectId=${projectId}&currency=${currency}&chainId=${chainId}`,
40+
`${baseUrl}/v1/account/${fulfilled_eth_address}/balance?projectId=${projectId}&currency=${currency}`,
4741
{
4842
headers: {
4943
'x-sdk-version': sdk_version,
@@ -53,6 +47,16 @@ describe('Account balance', () => {
5347
expect(resp.status).toBe(200)
5448
expect(typeof resp.data.balances).toBe('object')
5549
expect(resp.data.balances.length).toBeGreaterThan(1)
50+
})
51+
52+
it('fulfilled balance Solana address', async () => {
53+
let chainId = 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp'
54+
let resp: any = await httpClient.get(
55+
`${baseUrl}/v1/account/${fulfilled_solana_address}/balance?projectId=${projectId}&currency=${currency}&chainId=${chainId}&sv=${sdk_version}`
56+
)
57+
expect(resp.status).toBe(200)
58+
expect(typeof resp.data.balances).toBe('object')
59+
expect(resp.data.balances.length).toBeGreaterThan(1)
5660

5761
for (const item of resp.data.balances) {
5862
expect(item.chainId).toEqual(chainId)
@@ -76,12 +80,7 @@ describe('Account balance', () => {
7680

7781
it('empty balance Ethereum address', async () => {
7882
let resp: any = await httpClient.get(
79-
`${baseUrl}/v1/account/${empty_eth_address}/balance?projectId=${projectId}&currency=${currency}`,
80-
{
81-
headers: {
82-
'x-sdk-version': sdk_version,
83-
}
84-
}
83+
`${baseUrl}/v1/account/${empty_eth_address}/balance?projectId=${projectId}&currency=${currency}&sv=${sdk_version}`
8584
)
8685
expect(resp.status).toBe(200)
8786
expect(typeof resp.data.balances).toBe('object')
@@ -91,12 +90,7 @@ describe('Account balance', () => {
9190
it('empty balance Solana address', async () => {
9291
let chainId = 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp'
9392
let resp: any = await httpClient.get(
94-
`${baseUrl}/v1/account/${empty_solana_address}/balance?projectId=${projectId}&currency=${currency}&chainId=${chainId}`,
95-
{
96-
headers: {
97-
'x-sdk-version': sdk_version,
98-
}
99-
}
93+
`${baseUrl}/v1/account/${empty_solana_address}/balance?projectId=${projectId}&currency=${currency}&chainId=${chainId}&sv=${sdk_version}`
10094
)
10195
expect(resp.status).toBe(200)
10296
expect(typeof resp.data.balances).toBe('object')
@@ -107,12 +101,9 @@ describe('Account balance', () => {
107101
// USDC token contract address on Base
108102
const token_contract_address = 'eip155:8453:0x833589fcd6edb6e08f4c7c32d4f71b54bda02913'
109103
const endpoint = `/v1/account/${fulfilled_eth_address}/balance`;
110-
const queryParams = `?projectId=${projectId}&currency=${currency}&forceUpdate=${token_contract_address}`;
104+
const queryParams = `?projectId=${projectId}&currency=${currency}&sv=${sdk_version}&forceUpdate=${token_contract_address}`;
111105
const url = `${baseUrl}${endpoint}${queryParams}`;
112-
const headers = {
113-
'x-sdk-version': sdk_version,
114-
};
115-
let resp = await httpClient.get(url, { headers });
106+
let resp = await httpClient.get(url);
116107
expect(resp.status).toBe(200)
117108
expect(typeof resp.data.balances).toBe('object')
118109
expect(resp.data.balances.length).toBeGreaterThan(1)
@@ -140,20 +131,17 @@ describe('Account balance', () => {
140131
const zero_balance_address = '0x5b6262592954B925B510651462b63ddEbcc22eaD'
141132
const token_contract_address = 'eip155:8453:0x833589fcd6edb6e08f4c7c32d4f71b54bda02913'
142133
const endpoint = `/v1/account/${zero_balance_address}/balance`;
143-
let queryParams = `?projectId=${projectId}&currency=${currency}`;
134+
let queryParams = `?projectId=${projectId}&currency=${currency}&sv=${sdk_version}`;
144135
let url = `${baseUrl}${endpoint}${queryParams}`;
145-
const headers = {
146-
'x-sdk-version': sdk_version,
147-
};
148-
let resp = await httpClient.get(url, { headers });
136+
let resp = await httpClient.get(url);
149137
expect(resp.status).toBe(200)
150138
expect(typeof resp.data.balances).toBe('object')
151139
expect(resp.data.balances.length).toBe(0)
152140

153141
// Forcing update and checking injected balance in response
154142
queryParams = `${queryParams}&forceUpdate=${token_contract_address}`;
155143
url = `${baseUrl}${endpoint}${queryParams}`;
156-
resp = await httpClient.get(url, { headers });
144+
resp = await httpClient.get(url);
157145
expect(resp.status).toBe(200)
158146
expect(typeof resp.data.balances).toBe('object')
159147
expect(resp.data.balances.length).toBe(1)
@@ -167,12 +155,9 @@ describe('Account balance', () => {
167155
// We are using `0xe...` as a contract address for native tokens
168156
const token_contract_address = 'eip155:1:0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'
169157
const endpoint = `/v1/account/${fulfilled_eth_address}/balance`;
170-
const queryParams = `?projectId=${projectId}&currency=${currency}&forceUpdate=${token_contract_address}`;
158+
const queryParams = `?projectId=${projectId}&currency=${currency}&sv=${sdk_version}&forceUpdate=${token_contract_address}`;
171159
const url = `${baseUrl}${endpoint}${queryParams}`;
172-
const headers = {
173-
'x-sdk-version': sdk_version,
174-
};
175-
let resp = await httpClient.get(url, { headers });
160+
let resp = await httpClient.get(url);
176161
expect(resp.status).toBe(200)
177162
expect(typeof resp.data.balances).toBe('object')
178163
expect(resp.data.balances.length).toBeGreaterThan(1)

src/analytics/account_names_info.rs

+8
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ pub struct AccountNameRegistration {
1313
pub region: Option<String>,
1414
pub country: Option<Arc<str>>,
1515
pub continent: Option<Arc<str>>,
16+
17+
// Sdk info
18+
pub sv: Option<String>,
19+
pub st: Option<String>,
1620
}
1721

1822
impl AccountNameRegistration {
@@ -25,6 +29,8 @@ impl AccountNameRegistration {
2529
region: Option<Vec<String>>,
2630
country: Option<Arc<str>>,
2731
continent: Option<Arc<str>>,
32+
sv: Option<String>,
33+
st: Option<String>,
2834
) -> Self {
2935
Self {
3036
timestamp: wc::analytics::time::now(),
@@ -35,6 +41,8 @@ impl AccountNameRegistration {
3541
region: region.map(|r| r.join(", ")),
3642
country,
3743
continent,
44+
sv,
45+
st,
3846
}
3947
}
4048
}

src/analytics/balance_lookup_info.rs

+8
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ pub struct BalanceLookupInfo {
1919
pub region: Option<String>,
2020
pub country: Option<Arc<str>>,
2121
pub continent: Option<Arc<str>>,
22+
23+
// Sdk info
24+
pub sv: Option<String>,
25+
pub st: Option<String>,
2226
}
2327

2428
impl BalanceLookupInfo {
@@ -36,6 +40,8 @@ impl BalanceLookupInfo {
3640
region: Option<Vec<String>>,
3741
country: Option<Arc<str>>,
3842
continent: Option<Arc<str>>,
43+
sv: Option<String>,
44+
st: Option<String>,
3945
) -> Self {
4046
Self {
4147
timestamp: wc::analytics::time::now(),
@@ -51,6 +57,8 @@ impl BalanceLookupInfo {
5157
region: region.map(|r| r.join(", ")),
5258
country,
5359
continent,
60+
sv,
61+
st,
5462
}
5563
}
5664
}

src/analytics/history_lookup_info.rs

+8
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ pub struct HistoryLookupInfo {
2323
pub region: Option<String>,
2424
pub country: Option<Arc<str>>,
2525
pub continent: Option<Arc<str>>,
26+
27+
// Sdk info
28+
pub sv: Option<String>,
29+
pub st: Option<String>,
2630
}
2731

2832
impl HistoryLookupInfo {
@@ -39,6 +43,8 @@ impl HistoryLookupInfo {
3943
region: Option<Vec<String>>,
4044
country: Option<Arc<str>>,
4145
continent: Option<Arc<str>>,
46+
sv: Option<String>,
47+
st: Option<String>,
4248
) -> Self {
4349
HistoryLookupInfo {
4450
timestamp: wc::analytics::time::now(),
@@ -53,6 +59,8 @@ impl HistoryLookupInfo {
5359
region: region.map(|r| r.join(", ")),
5460
country,
5561
continent,
62+
sv,
63+
st,
5664
}
5765
}
5866
}

src/analytics/identity_lookup_info.rs

+9
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ pub struct IdentityLookupInfo {
2929

3030
pub client_id: Option<String>,
3131
pub sender: Option<String>,
32+
33+
// Sdk info
34+
pub sv: Option<String>,
35+
pub st: Option<String>,
3236
}
3337

3438
impl IdentityLookupInfo {
@@ -46,6 +50,8 @@ impl IdentityLookupInfo {
4650
continent: Option<Arc<str>>,
4751
client_id: Option<String>,
4852
sender: Option<String>,
53+
sv: Option<String>,
54+
st: Option<String>,
4955
) -> Self {
5056
Self {
5157
timestamp: wc::analytics::time::now(),
@@ -68,6 +74,9 @@ impl IdentityLookupInfo {
6874

6975
client_id,
7076
sender,
77+
78+
sv,
79+
st,
7180
}
7281
}
7382
}

src/analytics/message_info.rs

+9
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,14 @@ pub struct MessageInfo {
2222
pub region: Option<String>,
2323
pub country: Option<Arc<str>>,
2424
pub continent: Option<Arc<str>>,
25+
26+
// Sdk info
27+
pub sv: Option<String>,
28+
pub st: Option<String>,
2529
}
2630

2731
impl MessageInfo {
32+
#[allow(clippy::too_many_arguments)]
2833
pub fn new(
2934
query_params: &RpcQueryParams,
3035
request: &JsonRpcRequest,
@@ -33,6 +38,8 @@ impl MessageInfo {
3338
continent: Option<Arc<str>>,
3439
provider: &ProviderKind,
3540
origin: Option<String>,
41+
sv: Option<String>,
42+
st: Option<String>,
3643
) -> Self {
3744
Self {
3845
timestamp: wc::analytics::time::now(),
@@ -52,6 +59,8 @@ impl MessageInfo {
5259
region: region.map(|r| r.join(", ")),
5360
country,
5461
continent,
62+
sv,
63+
st,
5564
}
5665
}
5766
}

src/analytics/onramp_history_lookup_info.rs

+10
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ pub struct OnrampHistoryLookupInfo {
2222
pub purchase_currency: String,
2323
pub purchase_network: String,
2424
pub purchase_amount: String,
25+
26+
// Sdk info
27+
pub sv: Option<String>,
28+
pub st: Option<String>,
2529
}
2630

2731
impl OnrampHistoryLookupInfo {
@@ -40,6 +44,9 @@ impl OnrampHistoryLookupInfo {
4044
purchase_currency: String,
4145
purchase_network: String,
4246
purchase_amount: String,
47+
48+
sv: Option<String>,
49+
st: Option<String>,
4350
) -> Self {
4451
OnrampHistoryLookupInfo {
4552
transaction_id,
@@ -56,6 +63,9 @@ impl OnrampHistoryLookupInfo {
5663
purchase_currency,
5764
purchase_network,
5865
purchase_amount,
66+
67+
sv,
68+
st,
5969
}
6070
}
6171
}

src/handlers/balance.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use {
2-
super::{SupportedCurrencies, HANDLER_TASK_METRICS},
2+
super::{SdkInfoParams, SupportedCurrencies, HANDLER_TASK_METRICS},
33
crate::{
44
analytics::{BalanceLookupInfo, MessageSource},
55
error::RpcError,
@@ -43,6 +43,8 @@ pub struct BalanceQueryParams {
4343
pub chain_id: Option<String>,
4444
/// Comma separated list of CAIP-10 contract addresses to force update the balance
4545
pub force_update: Option<String>,
46+
#[serde(flatten)]
47+
pub sdk_info: SdkInfoParams,
4648
}
4749

4850
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
@@ -177,10 +179,10 @@ async fn handler_internal(
177179

178180
state.validate_project_access_and_quota(&project_id).await?;
179181

180-
// if headers not contains `x-sdk-version` then respond with an empty balance
181-
// array to fix the issue of redundant calls in sdk versions <= 4.1.8
182+
// if headers not contains `x-sdk-version` and `sv` query parameter then respond
183+
// with an empty balance array to fix the issue of redundant calls in sdk versions <= 4.1.8
182184
// https://github.com/WalletConnect/web3modal/pull/2157
183-
if !headers.contains_key("x-sdk-version") {
185+
if !headers.contains_key("x-sdk-version") && query.sdk_info.sv.is_none() {
184186
return Ok(Json(BalanceResponseBody { balances: vec![] }).into_response());
185187
}
186188

@@ -264,6 +266,8 @@ async fn handler_internal(
264266
region.clone(),
265267
country.clone(),
266268
continent.clone(),
269+
query.sdk_info.sv.clone(),
270+
query.sdk_info.st.clone(),
267271
));
268272
}
269273
}

src/handlers/history.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use {
2-
super::HANDLER_TASK_METRICS,
2+
super::{SdkInfoParams, HANDLER_TASK_METRICS},
33
crate::{
44
analytics::{HistoryLookupInfo, OnrampHistoryLookupInfo},
55
error::RpcError,
@@ -28,6 +28,8 @@ pub struct HistoryQueryParams {
2828
pub chain_id: Option<String>,
2929
pub cursor: Option<String>,
3030
pub onramp: Option<String>,
31+
#[serde(flatten)]
32+
pub sdk_info: SdkInfoParams,
3133
}
3234

3335
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
@@ -252,6 +254,8 @@ async fn handler_internal(
252254
region,
253255
country,
254256
continent,
257+
query.sdk_info.sv.clone(),
258+
query.sdk_info.st.clone(),
255259
));
256260
}
257261
ProviderKind::Coinbase => {
@@ -286,6 +290,8 @@ async fn handler_internal(
286290
.as_ref()
287291
.map(|v| v[0].quantity.numeric.clone())
288292
.unwrap_or_default(),
293+
query.sdk_info.sv.clone(),
294+
query.sdk_info.st.clone(),
289295
));
290296
}
291297
}

0 commit comments

Comments
 (0)