-
Notifications
You must be signed in to change notification settings - Fork 635
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Claimables [PR #1]: updates to query, types, utils, wallet screen ren…
…dering logic + wallet screen components (#6140) * updates to query, types, & wallet screen components * rm onPress * thanks greg
- Loading branch information
1 parent
0d07ede
commit b5588cb
Showing
10 changed files
with
158 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,50 @@ | ||
import { NativeCurrencyKey } from '@/entities'; | ||
import { AddysClaimable, Claimable } from './types'; | ||
import { convertRawAmountToBalance, convertRawAmountToNativeDisplay, greaterThan, lessThan } from '@/helpers/utilities'; | ||
import { convertRawAmountToBalance, convertRawAmountToNativeDisplay, greaterThan } from '@/helpers/utilities'; | ||
|
||
export const parseClaimables = (claimables: AddysClaimable[], currency: NativeCurrencyKey): Claimable[] => { | ||
return claimables | ||
.map(claimable => ({ | ||
name: claimable.name, | ||
uniqueId: claimable.unique_id, | ||
iconUrl: claimable.dapp.icon_url, | ||
value: { | ||
claimAsset: convertRawAmountToBalance(claimable.amount, claimable.asset), | ||
nativeAsset: convertRawAmountToNativeDisplay(claimable.amount, claimable.asset.decimals, claimable.asset.price.value, currency), | ||
}, | ||
})) | ||
.map(claimable => { | ||
if ( | ||
!(claimable.claim_action_type === 'transaction' || claimable.claim_action_type === 'sponsored') || | ||
!claimable.claim_action?.length | ||
) { | ||
return undefined; | ||
} | ||
|
||
const baseClaimable = { | ||
asset: { | ||
iconUrl: claimable.asset.icon_url, | ||
name: claimable.asset.name, | ||
symbol: claimable.asset.symbol, | ||
}, | ||
chainId: claimable.network, | ||
name: claimable.name, | ||
uniqueId: claimable.unique_id, | ||
iconUrl: claimable.dapp.icon_url, | ||
value: { | ||
claimAsset: convertRawAmountToBalance(claimable.amount, claimable.asset), | ||
nativeAsset: convertRawAmountToNativeDisplay(claimable.amount, claimable.asset.decimals, claimable.asset.price.value, currency), | ||
}, | ||
}; | ||
|
||
if (claimable.claim_action_type === 'transaction') { | ||
return { | ||
...baseClaimable, | ||
type: 'transaction' as const, | ||
action: { | ||
to: claimable.claim_action[0].address_to, | ||
data: claimable.claim_action[0].calldata, | ||
}, | ||
}; | ||
} else if (claimable.claim_action_type === 'sponsored') { | ||
return { | ||
...baseClaimable, | ||
type: 'sponsored' as const, | ||
action: { method: claimable.claim_action[0].method, url: claimable.claim_action[0].url }, | ||
}; | ||
} | ||
}) | ||
.filter((c): c is Claimable => !!c) | ||
.sort((a, b) => (greaterThan(a.value.claimAsset.amount ?? '0', b.value.claimAsset.amount ?? '0') ? -1 : 1)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.