Commit 8c3ec8d
authored
chore(predict): track success and error for pwat (#29512)
# **Description**
Currently `paymentTokenAddress` is only sent on the initial SUBMITTED
analytics event when a pay-with-any-token order enters the DEPOSITING
state. The second SUBMITTED (actual order placement), SUCCEEDED, and
FAILED events do not include it, and deposit failures fire no analytics
event at all.
This PR:
- Persists `paymentTokenAddress` on `activeBuyOrders[address]` when the
order begins (DEPOSITING and PLACING_ORDER transitions) so the value
survives `selectedPaymentToken` being cleared on error paths.
- Passes `paymentTokenAddress` to all three `trackPredictOrderEvent`
calls in `placeOrder()` — SUBMITTED, SUCCEEDED, and FAILED.
- Fires a new FAILED analytics event in `handleTransactionSideEffects`
when a `depositAndOrder` transaction fails, including
`paymentTokenAddress` from the stored active order.
## **Changelog**
CHANGELOG entry: null
## **Related issues**
Fixes:
## **Manual testing steps**
```gherkin
Feature: paymentTokenAddress tracked on order success and failure
Scenario: user places a pay-with-any-token order that succeeds
Given user is on the Predict buy screen with an external payment token selected
When user places a buy order and the order succeeds
Then the SUCCEEDED analytics event includes predict_token_address matching the selected token
Scenario: user places a pay-with-any-token order that fails
Given user is on the Predict buy screen with an external payment token selected
When user places a buy order and the order fails
Then the FAILED analytics event includes predict_token_address matching the selected token
Scenario: deposit-and-order transaction fails before order placement
Given user initiated a deposit-and-order flow with an external payment token
When the deposit transaction fails on-chain
Then a FAILED analytics event fires with predict_token_address from the stored active order
Scenario: user places a direct balance order
Given user is on the Predict buy screen with Predict balance selected (no external token)
When user places a buy order
Then the SUBMITTED, SUCCEEDED, and FAILED analytics events do not include predict_token_address
```
## **Screenshots/Recordings**
N/A — analytics-only change with no UI impact.
### **Before**
### **After**
## **Pre-merge author checklist**
- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I've included tests if applicable
- [ ] I've documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I've applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
## **Pre-merge reviewer checklist**
- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Touches the Predict order/deposit flow by persisting
`paymentTokenAddress` on `activeBuyOrders` and emitting additional
FAILED analytics on `depositAndOrder` failures; risk is mainly around
order-state transitions and potential null/incorrect token attribution,
not funds movement.
>
> **Overview**
> Ensures pay-with-any-token (PWAT) orders consistently attribute
analytics to the chosen payment token by persisting
`paymentTokenAddress` on `activeBuyOrders` during the
`DEPOSITING`/`PLACING_ORDER` transitions and reusing it even if
`selectedPaymentToken` is later cleared.
>
> Updates `placeOrder()` to pass `paymentTokenAddress` into the
SUBMITTED/SUCCEEDED/FAILED `trackPredictOrderEvent` calls for PWAT buys,
and adds a new FAILED analytics event when a `depositAndOrder`
transaction fails (sourced from the stored active order). Tests were
expanded to cover these new analytics/state behaviors and to ensure the
balance flow does not emit `predict_token_address`.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
b1fc91b. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent be0e59e commit 8c3ec8d
2 files changed
Lines changed: 270 additions & 0 deletions
Lines changed: 245 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7990 | 7990 | | |
7991 | 7991 | | |
7992 | 7992 | | |
| 7993 | + | |
| 7994 | + | |
| 7995 | + | |
| 7996 | + | |
| 7997 | + | |
| 7998 | + | |
| 7999 | + | |
| 8000 | + | |
| 8001 | + | |
| 8002 | + | |
| 8003 | + | |
| 8004 | + | |
| 8005 | + | |
| 8006 | + | |
| 8007 | + | |
| 8008 | + | |
| 8009 | + | |
| 8010 | + | |
| 8011 | + | |
| 8012 | + | |
| 8013 | + | |
| 8014 | + | |
| 8015 | + | |
| 8016 | + | |
| 8017 | + | |
| 8018 | + | |
| 8019 | + | |
| 8020 | + | |
| 8021 | + | |
| 8022 | + | |
| 8023 | + | |
| 8024 | + | |
| 8025 | + | |
| 8026 | + | |
| 8027 | + | |
| 8028 | + | |
| 8029 | + | |
| 8030 | + | |
| 8031 | + | |
| 8032 | + | |
| 8033 | + | |
| 8034 | + | |
| 8035 | + | |
| 8036 | + | |
| 8037 | + | |
| 8038 | + | |
| 8039 | + | |
| 8040 | + | |
| 8041 | + | |
| 8042 | + | |
| 8043 | + | |
| 8044 | + | |
| 8045 | + | |
| 8046 | + | |
| 8047 | + | |
| 8048 | + | |
| 8049 | + | |
| 8050 | + | |
| 8051 | + | |
| 8052 | + | |
| 8053 | + | |
| 8054 | + | |
| 8055 | + | |
| 8056 | + | |
| 8057 | + | |
| 8058 | + | |
| 8059 | + | |
| 8060 | + | |
| 8061 | + | |
| 8062 | + | |
| 8063 | + | |
| 8064 | + | |
| 8065 | + | |
| 8066 | + | |
| 8067 | + | |
| 8068 | + | |
| 8069 | + | |
| 8070 | + | |
| 8071 | + | |
| 8072 | + | |
| 8073 | + | |
| 8074 | + | |
| 8075 | + | |
| 8076 | + | |
| 8077 | + | |
| 8078 | + | |
| 8079 | + | |
| 8080 | + | |
| 8081 | + | |
| 8082 | + | |
| 8083 | + | |
| 8084 | + | |
| 8085 | + | |
| 8086 | + | |
| 8087 | + | |
| 8088 | + | |
| 8089 | + | |
| 8090 | + | |
| 8091 | + | |
| 8092 | + | |
| 8093 | + | |
| 8094 | + | |
| 8095 | + | |
| 8096 | + | |
| 8097 | + | |
| 8098 | + | |
| 8099 | + | |
| 8100 | + | |
| 8101 | + | |
| 8102 | + | |
| 8103 | + | |
| 8104 | + | |
| 8105 | + | |
| 8106 | + | |
| 8107 | + | |
| 8108 | + | |
| 8109 | + | |
| 8110 | + | |
| 8111 | + | |
| 8112 | + | |
| 8113 | + | |
| 8114 | + | |
| 8115 | + | |
| 8116 | + | |
| 8117 | + | |
| 8118 | + | |
| 8119 | + | |
| 8120 | + | |
| 8121 | + | |
| 8122 | + | |
| 8123 | + | |
| 8124 | + | |
| 8125 | + | |
| 8126 | + | |
| 8127 | + | |
| 8128 | + | |
| 8129 | + | |
| 8130 | + | |
| 8131 | + | |
| 8132 | + | |
| 8133 | + | |
| 8134 | + | |
| 8135 | + | |
| 8136 | + | |
| 8137 | + | |
| 8138 | + | |
| 8139 | + | |
| 8140 | + | |
| 8141 | + | |
| 8142 | + | |
| 8143 | + | |
| 8144 | + | |
| 8145 | + | |
| 8146 | + | |
| 8147 | + | |
| 8148 | + | |
| 8149 | + | |
| 8150 | + | |
| 8151 | + | |
| 8152 | + | |
| 8153 | + | |
| 8154 | + | |
| 8155 | + | |
| 8156 | + | |
| 8157 | + | |
| 8158 | + | |
| 8159 | + | |
| 8160 | + | |
| 8161 | + | |
| 8162 | + | |
| 8163 | + | |
| 8164 | + | |
| 8165 | + | |
| 8166 | + | |
| 8167 | + | |
| 8168 | + | |
| 8169 | + | |
| 8170 | + | |
| 8171 | + | |
| 8172 | + | |
| 8173 | + | |
| 8174 | + | |
| 8175 | + | |
| 8176 | + | |
| 8177 | + | |
7993 | 8178 | | |
7994 | 8179 | | |
7995 | 8180 | | |
| |||
9097 | 9282 | | |
9098 | 9283 | | |
9099 | 9284 | | |
| 9285 | + | |
| 9286 | + | |
| 9287 | + | |
| 9288 | + | |
| 9289 | + | |
| 9290 | + | |
| 9291 | + | |
| 9292 | + | |
| 9293 | + | |
| 9294 | + | |
| 9295 | + | |
| 9296 | + | |
| 9297 | + | |
| 9298 | + | |
| 9299 | + | |
| 9300 | + | |
| 9301 | + | |
| 9302 | + | |
| 9303 | + | |
| 9304 | + | |
| 9305 | + | |
| 9306 | + | |
| 9307 | + | |
| 9308 | + | |
| 9309 | + | |
| 9310 | + | |
| 9311 | + | |
| 9312 | + | |
| 9313 | + | |
| 9314 | + | |
| 9315 | + | |
| 9316 | + | |
| 9317 | + | |
| 9318 | + | |
| 9319 | + | |
| 9320 | + | |
| 9321 | + | |
| 9322 | + | |
| 9323 | + | |
| 9324 | + | |
| 9325 | + | |
| 9326 | + | |
| 9327 | + | |
| 9328 | + | |
| 9329 | + | |
| 9330 | + | |
| 9331 | + | |
| 9332 | + | |
| 9333 | + | |
| 9334 | + | |
| 9335 | + | |
| 9336 | + | |
| 9337 | + | |
| 9338 | + | |
| 9339 | + | |
| 9340 | + | |
| 9341 | + | |
| 9342 | + | |
| 9343 | + | |
| 9344 | + | |
9100 | 9345 | | |
9101 | 9346 | | |
9102 | 9347 | | |
| |||
Lines changed: 25 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
143 | 143 | | |
144 | 144 | | |
145 | 145 | | |
| 146 | + | |
146 | 147 | | |
147 | 148 | | |
148 | 149 | | |
| |||
1021 | 1022 | | |
1022 | 1023 | | |
1023 | 1024 | | |
| 1025 | + | |
| 1026 | + | |
1024 | 1027 | | |
1025 | 1028 | | |
1026 | 1029 | | |
| |||
1066 | 1069 | | |
1067 | 1070 | | |
1068 | 1071 | | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
1069 | 1075 | | |
1070 | 1076 | | |
1071 | 1077 | | |
1072 | 1078 | | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
1073 | 1084 | | |
1074 | 1085 | | |
1075 | 1086 | | |
| |||
1113 | 1124 | | |
1114 | 1125 | | |
1115 | 1126 | | |
| 1127 | + | |
1116 | 1128 | | |
1117 | 1129 | | |
1118 | 1130 | | |
| |||
1192 | 1204 | | |
1193 | 1205 | | |
1194 | 1206 | | |
| 1207 | + | |
1195 | 1208 | | |
1196 | 1209 | | |
1197 | 1210 | | |
| |||
1212 | 1225 | | |
1213 | 1226 | | |
1214 | 1227 | | |
| 1228 | + | |
1215 | 1229 | | |
1216 | 1230 | | |
1217 | 1231 | | |
| |||
2145 | 2159 | | |
2146 | 2160 | | |
2147 | 2161 | | |
| 2162 | + | |
| 2163 | + | |
| 2164 | + | |
| 2165 | + | |
| 2166 | + | |
| 2167 | + | |
| 2168 | + | |
| 2169 | + | |
| 2170 | + | |
| 2171 | + | |
| 2172 | + | |
2148 | 2173 | | |
2149 | 2174 | | |
2150 | 2175 | | |
| |||
0 commit comments