Commit 86633c5
authored
fix(bridge): fix: cp-7.47.3 prevent crash when viewing Solana asset details (#16770)
## **Description**
Fixes a crash that occurs when viewing asset details for Solana tokens
in the Bridge flow. The issue was caused by `getTokenDetails` assuming
all non-EVM asset addresses are already in CAIP format, when the Bridge
API sometimes returns raw Solana addresses.
## **Related issues**
Fixes #16734
Fixes
[SWAPS-2525](https://consensyssoftware.atlassian.net/browse/SWAPS-2525)
## **Manual testing steps**
1. Navigate to Bridge feature
2. Select Solana as source or destination chain
3. Select any Solana token from the token list
4. Tap on the asset detail info button
5. Verify the asset details screen loads without crashing
6. Verify contract address and other details display correctly
## **Screenshots/Recordings**
<!-- Add screenshots or recordings demonstrating the fix -->
**Before:**
https://github.com/user-attachments/assets/cf41e9fa-ae3d-4336-aefe-40017e831364
**After:**
https://github.com/user-attachments/assets/ccacf57e-1971-42c4-a3d7-a3978e7c954b
## **Pre-merge author checklist**
- [x] I've followed [MetaMask Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md)
- [x] I've clearly explained what problem this PR solves
- [x] I've linked the issue that this PR fixes
- [x] I've included manual testing steps
- [x] I've included screenshots/recordings if applicable
- [x] I've added unit tests if applicable
## **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 the issue linked above
- [ ] I've checked that all unit tests pass
## **Solution Details**
### **Root Cause**
The `getTokenDetails` function was calling `parseCaipAssetType` directly
on `asset.address` for non-EVM assets, assuming it was already in CAIP
format. However, the Bridge API sometimes returns raw Solana addresses
instead of CAIP-formatted addresses, causing `parseCaipAssetType` to
throw an error.
### **Fix Applied**
Implemented the same defensive approach used in
`useTokenHistoricalPrices`:
```typescript
// Detect if address is already in CAIP format
const isCaipAssetType = asset.address.startsWith(`${asset.chainId}`);
// Convert to CAIP format if needed
const normalizedCaipAssetTypeAddress = isCaipAssetType
? asset.address
: `${asset.chainId}/token:${asset.address}`;
```
### **Benefits**
- ✅ **Fixes crash**: Solana asset details now load without errors
- ✅ **Backward compatible**: Handles both raw and CAIP format addresses
- ✅ **Consistent pattern**: Uses same approach as
`useTokenHistoricalPrices`
- ✅ **Zero breaking changes**: All existing functionality preserved
- ✅ **Future-proof**: Works with any non-EVM chain automatically
### **Testing**
- Added comprehensive unit tests covering both scenarios
- All 12 tests pass including new test cases
- Verified with existing Bridge test suite
- Manual testing confirms crash is resolved
[SWAPS-2525]:
https://consensyssoftware.atlassian.net/browse/SWAPS-2525?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ1 parent aa2e03a commit 86633c5
File tree
3 files changed
+120
-21
lines changed- app/components/UI/AssetOverview/utils
3 files changed
+120
-21
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
Lines changed: 110 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
33 | 38 | | |
34 | 39 | | |
35 | 40 | | |
| |||
114 | 119 | | |
115 | 120 | | |
116 | 121 | | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
117 | 227 | | |
118 | 228 | | |
119 | 229 | | |
| |||
177 | 287 | | |
178 | 288 | | |
179 | 289 | | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | 290 | | |
201 | 291 | | |
202 | 292 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
13 | 21 | | |
14 | | - | |
| 22 | + | |
15 | 23 | | |
16 | 24 | | |
17 | 25 | | |
| |||
0 commit comments