diff --git a/package-lock.json b/package-lock.json index c44a6f9..b57fdbb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,6 +22,7 @@ "react": "^18.2.0", "react-countdown": "^2.3.5", "react-dom": "^18.2.0", + "toml": "^3.0.0", "zustand": "^4.3.7" }, "devDependencies": { diff --git a/package.json b/package.json index 116d7b8..140a907 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "blend-ui", - "version": "1.0.1", + "version": "1.0.2", "private": true, "type": "module", "scripts": { @@ -28,6 +28,7 @@ "react": "^18.2.0", "react-countdown": "^2.3.5", "react-dom": "^18.2.0", + "toml": "^3.0.0", "@stellar/stellar-sdk": "12.1.0", "zustand": "^4.3.7" }, diff --git a/src/components/backstop/BackstopAPY.tsx b/src/components/backstop/BackstopAPY.tsx index bbec5e8..b17a73a 100644 --- a/src/components/backstop/BackstopAPY.tsx +++ b/src/components/backstop/BackstopAPY.tsx @@ -36,7 +36,7 @@ export const BackstopAPY: React.FC = ({ poolId, sx, ...props }} > = ({ q4w, inTokens, poolId }) => { const { connected, walletAddress, backstopDequeueWithdrawal, backstopWithdraw } = useWallet(); + const { viewType } = useSettings(); + const TOTAL_QUEUE_TIME_SECONDS = 21 * 24 * 60 * 60; const [timeLeft, setTimeLeft] = useState( @@ -49,70 +52,85 @@ export const BackstopQueueItem: React.FC = ({ q4w, inTok }; return ( - - - {timeLeft > 0 ? ( - - - + + + {timeLeft > 0 ? ( + + + + + ) : ( + - - ) : ( - - )} - - - + )} + + + + + {toBalance(inTokens)} + + + BLND-USDC LP + + - {toBalance(inTokens)} - - - BLND-USDC LP + {timeLeft > 0 ? toTimeSpan(timeLeft) : 'Unlocked'} - - {timeLeft > 0 ? toTimeSpan(timeLeft) : 'Unlocked'} - - - handleClick(q4w.amount)} - palette={theme.palette.positive} - sx={{ height: '35px', width: '108px', margin: '12px', padding: '6px' }} - > - {timeLeft > 0 ? 'Unqueue' : 'Withdraw'} - - + {viewType === ViewType.REGULAR && ( + handleClick(q4w.amount)} + palette={theme.palette.positive} + sx={{ height: '35px', width: '108px', margin: '12px', padding: '6px' }} + > + {timeLeft > 0 ? 'Unqueue' : 'Withdraw'} + + )} + + {viewType !== ViewType.REGULAR && ( + + handleClick(q4w.amount)} + palette={theme.palette.positive} + sx={{ height: '35px', width: '100%', margin: '12px', padding: '6px' }} + > + {timeLeft > 0 ? 'Unqueue' : 'Withdraw'} + + + )} + ); }; diff --git a/src/external/stellar-toml.ts b/src/external/stellar-toml.ts index d3ca903..91aa436 100644 --- a/src/external/stellar-toml.ts +++ b/src/external/stellar-toml.ts @@ -1,5 +1,6 @@ import { Reserve } from '@blend-capital/blend-sdk'; import { Horizon, StellarToml } from '@stellar/stellar-sdk'; +import toml from 'toml'; export type StellarTokenMetadata = { assetId: string; @@ -25,7 +26,7 @@ export async function getTokenMetadataFromTOML( image: code ? `/icons/tokens/${code.toLowerCase()}.svg` : undefined, issuer: '', }; - let toml; + let stellarToml: any; if (!reserve.tokenMetadata.asset) { // set soroban token defaults @@ -62,11 +63,44 @@ export async function getTokenMetadataFromTOML( issuer: assetIssuer, }; } - /* 2. Use their domain from their API account and use it attempt to load their stellar.toml */ - toml = await StellarToml.Resolver.resolve(tokenAccountHomeDomain || ''); - if (toml.CURRENCIES) { + if (tokenAccountHomeDomain === 'stellar.org') { + // If the account is stellar.org, we can return the default stellar asset token metadata values + return { + ...iconData, + assetId, + code: assetCode, + issuer: assetIssuer, + }; + } + if (tokenAccountHomeDomain === 'circle.com') { + stellarToml = await fetch('https://www.circle.com/hubfs/stellar.toml.txt') + .then((response) => response.text()) + .then(async (text) => { + try { + const tomlObject = toml.parse(text); + return Promise.resolve(tomlObject); + } catch (e: any) { + return Promise.reject( + new Error( + `stellar.toml is invalid - Parsing error on line ${e.line}, column ${e.column}: ${e.message}` + ) + ); + } + }) + .catch((err: Error) => { + if (err.message.match(/^maxContentLength size/)) { + throw new Error(`stellar.toml file exceeds allowed size`); + } else { + throw err; + } + }); + } else { + /* 2. Use their domain from their API account and use it attempt to load their stellar.toml */ + stellarToml = await StellarToml.Resolver.resolve(tokenAccountHomeDomain || '', {}); + } + if (stellarToml.CURRENCIES) { /* If we find some currencies listed, check to see if they have the currency we're looking for listed */ - for (const { code: currencyCode, issuer, image } of toml.CURRENCIES) { + for (const { code: currencyCode, issuer, image } of stellarToml.CURRENCIES) { // Check if all necessary fields are available if ( currencyCode &&