-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add infastructure for long running tools and implement limit orders #168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
147 changes: 0 additions & 147 deletions
147
apps/agentic-chat/src/components/Portfolio/ActivityRow.tsx
This file was deleted.
Oops, something went wrong.
85 changes: 85 additions & 0 deletions
85
apps/agentic-chat/src/components/Portfolio/ActivityRow/ActivityRow.tsx
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| import { formatDistanceToNow } from 'date-fns' | ||
| import { ArrowRightLeft, Send, Timer } from 'lucide-react' | ||
|
|
||
| import { DrawerListItem } from '@/components/ui/DrawerListItem' | ||
| import { ToolCard } from '@/components/ui/ToolCard' | ||
| import { stopPropagationHandler } from '@/lib/eventHandlers' | ||
| import { getExplorerUrl } from '@/lib/explorers' | ||
| import { formatCryptoAmount } from '@/lib/number' | ||
| import { truncateAddress } from '@/lib/utils' | ||
| import type { ActivityItem } from '@/types/activity' | ||
|
|
||
| import { LimitOrderDetails } from './components/LimitOrderDetails' | ||
| import { SendDetails } from './components/SendDetails' | ||
| import { SwapDetails } from './components/SwapDetails' | ||
|
|
||
| type ActivityRowProps = { | ||
| activity: ActivityItem | ||
| } | ||
|
|
||
| const ACTIVITY_ICONS = { | ||
| swap: ArrowRightLeft, | ||
| send: Send, | ||
| limit_order: Timer, | ||
| } | ||
|
|
||
| function formatActivityTitle(activity: ActivityItem): string { | ||
| switch (activity.type) { | ||
| case 'swap': | ||
| return `Swapped ${formatCryptoAmount(activity.details.sellAsset.amount, { symbol: activity.details.sellAsset.symbol })} to ${formatCryptoAmount(activity.details.buyAsset.amount, { symbol: activity.details.buyAsset.symbol })}` | ||
| case 'send': | ||
| return `Sent ${formatCryptoAmount(activity.details.asset.amount, { symbol: activity.details.asset.symbol })}` | ||
| case 'limit_order': | ||
| return `Limit order: ${formatCryptoAmount(activity.details.sellAsset.amount, { symbol: activity.details.sellAsset.symbol })} → ${formatCryptoAmount(activity.details.buyAsset.estimatedAmount, { symbol: activity.details.buyAsset.symbol })}` | ||
| } | ||
| } | ||
|
|
||
| function ActivityDetails({ activity }: { activity: ActivityItem }) { | ||
| const txHash = activity.type !== 'limit_order' ? activity.txHash : undefined | ||
| const explorerUrl = txHash ? getExplorerUrl(activity.network, txHash) : undefined | ||
|
|
||
| return ( | ||
| <ToolCard.Details> | ||
| {explorerUrl && txHash && ( | ||
| <ToolCard.DetailItem | ||
| label="TX ID" | ||
| value={ | ||
| <a | ||
| href={explorerUrl} | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| className="font-mono text-sm text-blue-500 hover:text-blue-400 transition-colors" | ||
| onClick={stopPropagationHandler} | ||
| > | ||
| {truncateAddress(txHash, 8, 6)} | ||
| </a> | ||
| } | ||
| /> | ||
| )} | ||
| {activity.type === 'swap' && <SwapDetails details={activity.details} network={activity.network} />} | ||
| {activity.type === 'send' && <SendDetails details={activity.details} />} | ||
| {activity.type === 'limit_order' && <LimitOrderDetails details={activity.details} />} | ||
| </ToolCard.Details> | ||
| ) | ||
| } | ||
|
|
||
| export function ActivityRow({ activity }: ActivityRowProps) { | ||
| const Icon = ACTIVITY_ICONS[activity.type] | ||
|
|
||
| return ( | ||
| <DrawerListItem expandedChildren={<ActivityDetails activity={activity} />}> | ||
| <div className="flex-shrink-0"> | ||
| <div className="w-10 h-10 rounded-full bg-primary/10 flex items-center justify-center"> | ||
| <Icon className="w-5 h-5 text-primary" /> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div className="flex-1 min-w-0"> | ||
| <div className="font-medium text-sm text-foreground truncate">{formatActivityTitle(activity)}</div> | ||
| <div className="text-xs text-muted-foreground"> | ||
| {formatDistanceToNow(activity.timestamp, { addSuffix: true })} | ||
| </div> | ||
| </div> | ||
| </DrawerListItem> | ||
| ) | ||
| } |
43 changes: 43 additions & 0 deletions
43
apps/agentic-chat/src/components/Portfolio/ActivityRow/components/LimitOrderDetails.tsx
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import { Amount } from '@/components/ui/Amount' | ||
| import { ToolCard } from '@/components/ui/ToolCard' | ||
| import { stopPropagationHandler } from '@/lib/eventHandlers' | ||
| import type { LimitOrderActivityDetails } from '@/types/activity' | ||
|
|
||
| type LimitOrderDetailsProps = { | ||
| details: LimitOrderActivityDetails | ||
| } | ||
|
|
||
| export function LimitOrderDetails({ details }: LimitOrderDetailsProps) { | ||
| return ( | ||
| <> | ||
| <ToolCard.DetailItem | ||
| label="Sell" | ||
| value={<Amount.Crypto value={details.sellAsset.amount} symbol={details.sellAsset.symbol} />} | ||
| /> | ||
| <ToolCard.DetailItem | ||
| label="Buy (estimated)" | ||
| value={<Amount.Crypto value={details.buyAsset.estimatedAmount} symbol={details.buyAsset.symbol} />} | ||
| /> | ||
| <ToolCard.DetailItem | ||
| label="Limit Price" | ||
| value={`1 ${details.sellAsset.symbol} = ${details.limitPrice} ${details.buyAsset.symbol}`} | ||
| /> | ||
| <ToolCard.DetailItem label="Expires" value={new Date(details.expiresAt).toLocaleString()} /> | ||
| <ToolCard.DetailItem label="Provider" value={details.provider.toUpperCase()} /> | ||
| <ToolCard.DetailItem | ||
| label="Track Order" | ||
| value={ | ||
| <a | ||
| href={details.trackingUrl} | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| className="text-sm text-blue-500 hover:text-blue-400 transition-colors" | ||
| onClick={stopPropagationHandler} | ||
| > | ||
| View on CoW Explorer | ||
| </a> | ||
| } | ||
| /> | ||
| </> | ||
| ) | ||
| } | ||
24 changes: 24 additions & 0 deletions
24
apps/agentic-chat/src/components/Portfolio/ActivityRow/components/SendDetails.tsx
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { Amount } from '@/components/ui/Amount' | ||
| import { ToolCard } from '@/components/ui/ToolCard' | ||
| import { truncateAddress } from '@/lib/utils' | ||
| import type { SendActivityDetails } from '@/types/activity' | ||
|
|
||
| type SendDetailsProps = { | ||
| details: SendActivityDetails | ||
| } | ||
|
|
||
| export function SendDetails({ details }: SendDetailsProps) { | ||
| return ( | ||
| <> | ||
| <ToolCard.DetailItem | ||
| label="Amount" | ||
| value={<Amount.Crypto value={details.asset.amount} symbol={details.asset.symbol} />} | ||
| /> | ||
| <ToolCard.DetailItem label="From" value={truncateAddress(details.from)} /> | ||
| <ToolCard.DetailItem label="To" value={truncateAddress(details.to)} /> | ||
| {details.fee && ( | ||
| <ToolCard.DetailItem label="Fee" value={<Amount.Crypto value={details.fee} symbol={details.feeSymbol} />} /> | ||
| )} | ||
| </> | ||
| ) | ||
| } | ||
|
premiumjibles marked this conversation as resolved.
|
||
66 changes: 66 additions & 0 deletions
66
apps/agentic-chat/src/components/Portfolio/ActivityRow/components/SwapDetails.tsx
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import { Amount } from '@/components/ui/Amount' | ||
| import { ToolCard } from '@/components/ui/ToolCard' | ||
| import { stopPropagationHandler } from '@/lib/eventHandlers' | ||
| import { getExplorerUrl } from '@/lib/explorers' | ||
| import { truncateAddress } from '@/lib/utils' | ||
| import type { SwapActivityDetails } from '@/types/activity' | ||
|
|
||
| type SwapDetailsProps = { | ||
| details: SwapActivityDetails | ||
| network: string | ||
| } | ||
|
|
||
| export function SwapDetails({ details, network }: SwapDetailsProps) { | ||
| const approvalExplorerUrl = details.approval ? getExplorerUrl(network, details.approval.txHash) : undefined | ||
|
|
||
| return ( | ||
| <> | ||
| <ToolCard.DetailItem | ||
| label="Sold" | ||
| value={ | ||
| <Amount.Crypto | ||
| value={details.sellAsset.amount} | ||
| symbol={details.sellAsset.symbol} | ||
| suffix={ | ||
| <> | ||
| (<Amount.Fiat value={details.sellAsset.valueUSD} />) | ||
| </> | ||
| } | ||
| /> | ||
| } | ||
| /> | ||
| <ToolCard.DetailItem | ||
| label="Received" | ||
| value={ | ||
| <Amount.Crypto | ||
| value={details.buyAsset.amount} | ||
| symbol={details.buyAsset.symbol} | ||
| suffix={ | ||
| <> | ||
| (<Amount.Fiat value={details.buyAsset.valueUSD} />) | ||
| </> | ||
| } | ||
| /> | ||
| } | ||
| /> | ||
| <ToolCard.DetailItem label="DEX" value={details.dex} /> | ||
| {details.fee && <ToolCard.DetailItem label="Fee" value={<Amount.Fiat value={details.fee} />} />} | ||
| {details.approval && approvalExplorerUrl && ( | ||
| <ToolCard.DetailItem | ||
| label="Approval TX" | ||
| value={ | ||
| <a | ||
| href={approvalExplorerUrl} | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| className="font-mono text-sm text-blue-500 hover:text-blue-400 transition-colors" | ||
| onClick={stopPropagationHandler} | ||
| > | ||
| {truncateAddress(details.approval.txHash, 8, 6)} | ||
| </a> | ||
| } | ||
| /> | ||
| )} | ||
| </> | ||
| ) | ||
| } |
1 change: 1 addition & 0 deletions
1
apps/agentic-chat/src/components/Portfolio/ActivityRow/index.ts
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { ActivityRow } from './ActivityRow' |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.