Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
interface
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
LuckySwap
interface
Commits
3a4dc91e
Unverified
Commit
3a4dc91e
authored
Sep 29, 2023
by
eddie
Committed by
GitHub
Sep 29, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: wrap/unwrap activity parsing (#7384)
* fix: add unit test * fix: re-use swap parse logic
parent
af800799
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
137 additions
and
0 deletions
+137
-0
parseRemote.test.tsx.snap
...ortfolio/Activity/__snapshots__/parseRemote.test.tsx.snap
+36
-0
activity.ts
...AccountDrawer/MiniPortfolio/Activity/fixtures/activity.ts
+81
-0
parseRemote.test.tsx
...AccountDrawer/MiniPortfolio/Activity/parseRemote.test.tsx
+5
-0
parseRemote.tsx
...ents/AccountDrawer/MiniPortfolio/Activity/parseRemote.tsx
+15
-0
No files found.
src/components/AccountDrawer/MiniPortfolio/Activity/__snapshots__/parseRemote.test.tsx.snap
View file @
3a4dc91e
...
...
@@ -101,6 +101,42 @@ Object {
}
`;
exports[`parseRemote parseRemoteActivities should parse eth wrap 1`] = `
Object {
"chainId": 1,
"currencies": Array [
ExtendedEther {
"chainId": 1,
"decimals": 18,
"isNative": true,
"isToken": false,
"name": "Ether",
"symbol": "ETH",
},
Token {
"address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
"chainId": 1,
"decimals": 18,
"isNative": false,
"isToken": true,
"name": "Wrapped Ether",
"symbol": "WETH",
},
],
"descriptor": "100 ETH for 100 WETH",
"from": "0x50EC05ADe8280758E2077fcBC08D878D4aef79C3",
"hash": "someHash",
"logos": Array [
"https://token-icons.s3.amazonaws.com/eth.png",
"https://raw.githubusercontent.com/Uniswap/assets/master/blockchains/ethereum/assets/0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2/logo.png",
],
"nonce": 12345,
"status": "CONFIRMED",
"timestamp": 10000,
"title": "Wrapped",
}
`;
exports[`parseRemote parseRemoteActivities should parse moonpay purchase 1`] = `
Object {
"chainId": 1,
...
...
src/components/AccountDrawer/MiniPortfolio/Activity/fixtures/activity.ts
View file @
3a4dc91e
...
...
@@ -222,6 +222,78 @@ const mockTokenTransferOutPartsFragment = {
},
}
const
mockNativeTokenTransferOutPartsFragment
=
{
__typename
:
'
TokenTransfer
'
,
id
:
'
tokenTransferId
'
,
asset
:
{
__typename
:
'
Token
'
,
id
:
'
ETH
'
,
name
:
'
Ether
'
,
symbol
:
'
ETH
'
,
address
:
null
,
decimals
:
18
,
chain
:
'
ETHEREUM
'
,
standard
:
null
,
project
:
{
__typename
:
'
TokenProject
'
,
id
:
'
Ethereum
'
,
isSpam
:
false
,
logo
:
{
__typename
:
'
Image
'
,
id
:
'
ETH_logo
'
,
url
:
'
https://token-icons.s3.amazonaws.com/eth.png
'
,
},
},
},
tokenStandard
:
'
NATIVE
'
,
quantity
:
'
0.25
'
,
sender
:
MockSenderAddress
,
recipient
:
MockRecipientAddress
,
direction
:
'
OUT
'
,
transactedValue
:
{
__typename
:
'
Amount
'
,
id
:
'
ETH_amount
'
,
currency
:
'
USD
'
,
value
:
399.0225
,
},
}
const
mockWrappedEthTransferInPartsFragment
=
{
__typename
:
'
TokenTransfer
'
,
id
:
'
tokenTransferId
'
,
asset
:
{
__typename
:
'
Token
'
,
id
:
'
WETH
'
,
name
:
'
Wrapped Ether
'
,
symbol
:
'
WETH
'
,
address
:
'
0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
'
,
decimals
:
18
,
chain
:
'
ETHEREUM
'
,
standard
:
'
ERC20
'
,
project
:
{
__typename
:
'
TokenProject
'
,
id
:
'
weth_project_id
'
,
isSpam
:
false
,
logo
:
{
__typename
:
'
Image
'
,
id
:
'
weth_image
'
,
url
:
'
https://raw.githubusercontent.com/Uniswap/assets/master/blockchains/ethereum/assets/0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2/logo.png
'
,
},
},
},
tokenStandard
:
'
ERC20
'
,
quantity
:
'
0.25
'
,
sender
:
MockSenderAddress
,
recipient
:
MockRecipientAddress
,
direction
:
'
IN
'
,
transactedValue
:
{
__typename
:
'
Amount
'
,
id
:
'
mockWethAmountId
'
,
currency
:
'
USD
'
,
value
:
399.1334007875
,
},
}
const
mockTokenTransferInPartsFragment
=
{
__typename
:
'
TokenTransfer
'
,
id
:
'
tokenTransferId
'
,
...
...
@@ -439,3 +511,12 @@ export const MockNFTPurchase = {
],
},
}
as
AssetActivityPartsFragment
export
const
MockWrap
=
{
...
mockAssetActivityPartsFragment
,
details
:
{
...
commonTransactionDetailsFields
,
type
:
TransactionType
.
Lend
,
assetChanges
:
[
mockNativeTokenTransferOutPartsFragment
,
mockWrappedEthTransferInPartsFragment
],
},
}
as
AssetActivityPartsFragment
src/components/AccountDrawer/MiniPortfolio/Activity/parseRemote.test.tsx
View file @
3a4dc91e
...
...
@@ -16,6 +16,7 @@ import {
MockTokenReceive
,
MockTokenSend
,
MockTokenTransfer
,
MockWrap
,
}
from
'
./fixtures/activity
'
import
{
parseRemoteActivities
,
useTimeSince
}
from
'
./parseRemote
'
...
...
@@ -80,6 +81,10 @@ describe('parseRemote', () => {
const
result
=
parseRemoteActivities
(
jest
.
fn
().
mockReturnValue
(
'
100
'
),
[
MockSwapOrder
])
expect
(
result
?.[
'
someHash
'
]).
toMatchSnapshot
()
})
it
(
'
should parse eth wrap
'
,
()
=>
{
const
result
=
parseRemoteActivities
(
jest
.
fn
().
mockReturnValue
(
'
100
'
),
[
MockWrap
])
expect
(
result
?.[
'
someHash
'
]).
toMatchSnapshot
()
})
})
describe
(
'
useTimeSince
'
,
()
=>
{
...
...
src/components/AccountDrawer/MiniPortfolio/Activity/parseRemote.tsx
View file @
3a4dc91e
...
...
@@ -182,6 +182,19 @@ function parseSwap(changes: TransactionChanges, formatNumberOrString: FormatNumb
return
{
title
:
t
`Unknown Swap`
}
}
/**
* Wrap/unwrap transactions are labelled as lend transactions on the backend.
* This function parses the transaction changes to determine if the transaction is a wrap/unwrap transaction.
*/
function
parseLend
(
changes
:
TransactionChanges
,
formatNumberOrString
:
FormatNumberOrStringFunctionType
)
{
const
native
=
changes
.
TokenTransfer
.
find
((
t
)
=>
t
.
tokenStandard
===
'
NATIVE
'
)?.
asset
const
erc20
=
changes
.
TokenTransfer
.
find
((
t
)
=>
t
.
tokenStandard
===
'
ERC20
'
)?.
asset
if
(
native
&&
erc20
&&
gqlToCurrency
(
native
)?.
wrapped
.
address
===
gqlToCurrency
(
erc20
)?.
wrapped
.
address
)
{
return
parseSwap
(
changes
,
formatNumberOrString
)
}
return
{
title
:
t
`Unknown Lend`
}
}
function
parseSwapOrder
(
changes
:
TransactionChanges
,
formatNumberOrString
:
FormatNumberOrStringFunctionType
)
{
return
{
...
parseSwap
(
changes
,
formatNumberOrString
),
prefixIconSrc
:
UniswapXBolt
}
}
...
...
@@ -305,6 +318,7 @@ type ActivityTypeParser = (
)
=>
Partial
<
Activity
>
const
ActivityParserByType
:
{
[
key
:
string
]:
ActivityTypeParser
|
undefined
}
=
{
[
ActivityType
.
Swap
]:
parseSwap
,
[
ActivityType
.
Lend
]:
parseLend
,
[
ActivityType
.
SwapOrder
]:
parseSwapOrder
,
[
ActivityType
.
Approve
]:
parseApprove
,
[
ActivityType
.
Send
]:
parseSendReceive
,
...
...
@@ -395,6 +409,7 @@ function parseRemoteActivity(
})
return
undefined
}
const
defaultFields
=
{
hash
:
assetActivity
.
details
.
hash
,
chainId
:
supportedChain
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment