Skip to content

Commit

Permalink
Transfer limit information (#557)
Browse files Browse the repository at this point in the history
* base bridge get token and chain

* transfer limit info
  • Loading branch information
JayJay1024 authored Nov 2, 2023
1 parent f06a917 commit be5125a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
16 changes: 16 additions & 0 deletions packages/apps/src/bridges/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,22 @@ export abstract class BaseBridge {
return this.contract;
}

getSourceToken() {
return this.sourceToken;
}

getTargetToken() {
return this.targetToken;
}

getSourceChain() {
return this.sourceChain;
}

getTargetChain() {
return this.targetChain;
}

getEstimateTime() {
return this.estimateTime;
}
Expand Down
24 changes: 23 additions & 1 deletion packages/apps/src/components/cross-chain-info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,25 @@ import { Subscription, from } from "rxjs";
interface Props {
fee: { loading: boolean; value: bigint; token?: Token } | undefined;
bridge: BaseBridge | undefined;
maxMargin: string | undefined;
isLoadingMaxMargin: boolean;
}

export default function CrossChainInfo({ fee, bridge }: Props) {
export default function CrossChainInfo({ fee, bridge, maxMargin, isLoadingMaxMargin }: Props) {
const [transferLimit, setTransferLimit] = useState<{ token: Token; value: bigint }>();
const [dailyLimit, setDailyLimit] = useState<{ loading: boolean; limit: bigint; spent: bigint; token: Token }>();

useEffect(() => {
if (!isLoadingMaxMargin) {
const token = bridge?.getSourceToken();
if (maxMargin && token) {
setTransferLimit({ token, value: BigInt(maxMargin) });
} else {
setTransferLimit(undefined);
}
}
}, [bridge, maxMargin, isLoadingMaxMargin]);

useEffect(() => {
let sub$$: Subscription | undefined;
if (bridge) {
Expand Down Expand Up @@ -54,6 +68,14 @@ export default function CrossChainInfo({ fee, bridge }: Props) {
</Tooltip>
)}
</Item>
{!!transferLimit && (
<Item>
<span>Transfer Limit</span>
<span>
{formatBalance(transferLimit.value, transferLimit.token.decimals)} {transferLimit.token.symbol}
</span>
</Item>
)}
{!!dailyLimit && (
<Item>
<span>Daily Limit</span>
Expand Down
2 changes: 2 additions & 0 deletions packages/apps/src/components/transfer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ export default function Transfer() {
<CrossChainInfo
fee={fee ? { ...fee, loading: isLoadingFee || isLoadingRelayers } : undefined}
bridge={bridgeClient}
maxMargin={relayersData?.sortedLnv20RelayInfos?.maxMargin}
isLoadingMaxMargin={isLoadingRelayers}
/>
</Section>

Expand Down

0 comments on commit be5125a

Please sign in to comment.