Merge pull request #912 from secretkeylabs/chore/fix-merge-conflicts

fix: resolve merge conflicts
This commit is contained in:
Duska.T
2025-02-06 10:22:22 +01:00
committed by GitHub
10 changed files with 180 additions and 254 deletions

View File

@@ -1,63 +1,49 @@
# 🔘 PR Type
What kind of change does this PR introduce?
<!-- Please check the one that applies to this PR using "x". -->
- [ ] Bugfix
- [ ] Enhancement
- [ ] Code style update (formatting, local variables)
- [ ] Refactoring (no functional changes, no API changes)
- [ ] Build related changes
- [ ] CI related changes
- [ ] Documentation content changes
- [ ] Other... Please describe:
# 📜 Background
Provide a brief explanation of why this pull request is needed. Include the problem you are solving or the functionality you are adding. Reference any related issues.
Issue Link: #[issue_number]
Context Link (if applicable):
# 🔄 Changes
Enumerate the changes made in this pull request, detailing what has been modified, added, or removed. Include technical details and implications if necessary.
Impact:
- Explain the broader impact of these changes.
- How it improves performance, fixes bugs, adds functionality, etc.
# 🧪 E2E Test Result
Include a screenshot of the e2e test result.
`Run E2E Tests`
Our End-to-end (E2E) test suite is build with Playwright. To run the whole E2E test suite, run:
`npm run e2etest`
If you only want to run the smoke test suite, run
`npm run e2etest:smoketest`
If you want to run the e2e test in UI Mode:
`npm run e2etest:ui`
To generate test report, run:
`npm run e2etest:report`
# Summary
Link to Linear issue (if not linked by bot):
- [ ] PR Title was updated to match: `<branch_type>: <descriptive, short message of what work was done> [<parent issue ID1>][<parent issue ID2>]`
[See Branch types here](https://www.notion.so/xverseapp/Xverse-Contributing-1215520b9dee80cb9497f6866a99e2f4?pvs=4#1365520b9dee80f78f9ecd9f0bb23a8f)
# 🖼 Screenshot / 📹 Video
Include screenshots or a video demonstrating the changes. This is especially helpful for UI changes.
| Before | After |
| :---: | :---: |
|<img width="50%" alt="" src="" />|<img width="50%" alt="" src="" />|
# ✅ Review checklist
# 🔄 Changes
- What has been added, modified removed?
- Where was the fix?
- Include technical details and implications if necessary.
- What xverse-core changes were included?
Please ensure the following are true before merging:
Impact:
- Explain the broader impact of these changes.
- Which areas of the application have been touched?
- What should the tester be aware of when testing?
- What can help the reviewer to be aware of when reading the code?
- What are the security implications?
- [ ] Code Style is consistent with the project guidelines.
- [ ] Code is readable and well-commented.
- [ ] No unnecessary or debugging code has been added.
- [ ] Security considerations have been taken into account.
- [ ] The change has been manually tested and works as expected.
- [ ] Breaking changes and their impacts have been considered and documented.
- [ ] Code does not introduce new technical debt or issues.
# 🔍 Testing Steps
1. How to set up testing of the changes
2. What steps to test
3. What is expected
- [ ] Does this need QA? (If so, add the label `Ready for test`) [See considerations here](https://www.notion.so/xverseapp/Xverse-Contributing-1215520b9dee80cb9497f6866a99e2f4?pvs=4#13e5520b9dee80938816fa66214541db)
# ✅ Author checklist (can be draft if not all ready)
Please ensure the following are true before submitting for review:
- [ ] The PR template has been filled.
- [ ] E2E tests or unit tests have been added/updated.
- [ ] The changes have been self-reviewed, and has been tidied up for an easy peer review.
- [ ] No debugging code
- [ ] No out of scope changes
- [ ] Should the PR be split up for easier review?
- [ ] The change has been manually tested and works as expected.
- [ ] The PR has been labeled/flagged for QA if necessary.
# ✅ Reviewer checklist
- [ ] The changes follow the intended scope.
- [ ] Code is clean and readable. No anti-patterns, no code smells.
- [ ] Code structure maintains separation of concerns.
- [ ] Check that code does not belong in xverse-core, or also on mobile.
- [ ] E2E tests or unit tests have been added/updated.
- [ ] (If no QA) The PR has been manually tested and works as expected.

168
package-lock.json generated
View File

@@ -140,19 +140,6 @@
"node": ">=0.10.0"
}
},
"node_modules/@ampproject/remapping": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.2.1.tgz",
"integrity": "sha512-lFMjJTrFL3j7L9yBxwYfCq2k6qqwHyzuUl/XBnif78PWTJYyL/dfowQHWE3sp6U6ZzqWiiIZnpTMO96zhkjwtg==",
"peer": true,
"dependencies": {
"@jridgewell/gen-mapping": "^0.3.0",
"@jridgewell/trace-mapping": "^0.3.9"
},
"engines": {
"node": ">=6.0.0"
}
},
"node_modules/@aryzing/superqs": {
"version": "0.0.6",
"resolved": "https://registry.npmjs.org/@aryzing/superqs/-/superqs-0.0.6.tgz",
@@ -173,51 +160,6 @@
"node": ">=6.9.0"
}
},
"node_modules/@babel/compat-data": {
"version": "7.23.3",
"resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.23.3.tgz",
"integrity": "sha512-BmR4bWbDIoFJmJ9z2cZ8Gmm2MXgEDgjdWgpKmKWUt54UGFJdlj31ECtbaDvCG/qVdG3AQ1SfpZEs01lUFbzLOQ==",
"peer": true,
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/@babel/core": {
"version": "7.23.3",
"resolved": "https://registry.npmjs.org/@babel/core/-/core-7.23.3.tgz",
"integrity": "sha512-Jg+msLuNuCJDyBvFv5+OKOUjWMZgd85bKjbICd3zWrKAo+bJ49HJufi7CQE0q0uR8NGyO6xkCACScNqyjHSZew==",
"peer": true,
"dependencies": {
"@ampproject/remapping": "^2.2.0",
"@babel/code-frame": "^7.22.13",
"@babel/generator": "^7.23.3",
"@babel/helper-compilation-targets": "^7.22.15",
"@babel/helper-module-transforms": "^7.23.3",
"@babel/helpers": "^7.23.2",
"@babel/parser": "^7.23.3",
"@babel/template": "^7.22.15",
"@babel/traverse": "^7.23.3",
"@babel/types": "^7.23.3",
"convert-source-map": "^2.0.0",
"debug": "^4.1.0",
"gensync": "^1.0.0-beta.2",
"json5": "^2.2.3",
"semver": "^6.3.1"
},
"engines": {
"node": ">=6.9.0"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/babel"
}
},
"node_modules/@babel/core/node_modules/convert-source-map": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-2.0.0.tgz",
"integrity": "sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==",
"peer": true
},
"node_modules/@babel/generator": {
"version": "7.23.4",
"resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.23.4.tgz",
@@ -243,22 +185,6 @@
"node": ">=6.9.0"
}
},
"node_modules/@babel/helper-compilation-targets": {
"version": "7.22.15",
"resolved": "https://registry.npmjs.org/@babel/helper-compilation-targets/-/helper-compilation-targets-7.22.15.tgz",
"integrity": "sha512-y6EEzULok0Qvz8yyLkCvVX+02ic+By2UdOhylwUOvOn9dvYc9mKICJuuU1n1XBI02YWsNsnrY1kc6DVbjcXbtw==",
"peer": true,
"dependencies": {
"@babel/compat-data": "^7.22.9",
"@babel/helper-validator-option": "^7.22.15",
"browserslist": "^4.21.9",
"lru-cache": "^5.1.1",
"semver": "^6.3.1"
},
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/@babel/helper-environment-visitor": {
"version": "7.22.20",
"resolved": "https://registry.npmjs.org/@babel/helper-environment-visitor/-/helper-environment-visitor-7.22.20.tgz",
@@ -301,25 +227,6 @@
"node": ">=6.9.0"
}
},
"node_modules/@babel/helper-module-transforms": {
"version": "7.23.3",
"resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.23.3.tgz",
"integrity": "sha512-7bBs4ED9OmswdfDzpz4MpWgSrV7FXlc3zIagvLFjS5H+Mk7Snr21vQ6QwrsoCGMfNC4e4LQPdoULEt4ykz0SRQ==",
"peer": true,
"dependencies": {
"@babel/helper-environment-visitor": "^7.22.20",
"@babel/helper-module-imports": "^7.22.15",
"@babel/helper-simple-access": "^7.22.5",
"@babel/helper-split-export-declaration": "^7.22.6",
"@babel/helper-validator-identifier": "^7.22.20"
},
"engines": {
"node": ">=6.9.0"
},
"peerDependencies": {
"@babel/core": "^7.0.0"
}
},
"node_modules/@babel/helper-plugin-utils": {
"version": "7.22.5",
"resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.22.5.tgz",
@@ -328,18 +235,6 @@
"node": ">=6.9.0"
}
},
"node_modules/@babel/helper-simple-access": {
"version": "7.22.5",
"resolved": "https://registry.npmjs.org/@babel/helper-simple-access/-/helper-simple-access-7.22.5.tgz",
"integrity": "sha512-n0H99E/K+Bika3++WNL17POvo4rKWZ7lZEp1Q+fStVbUi8nxPQEBOlTmCOxW/0JsS56SKKQ+ojAe2pHKJHN35w==",
"peer": true,
"dependencies": {
"@babel/types": "^7.22.5"
},
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/@babel/helper-split-export-declaration": {
"version": "7.22.6",
"resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.22.6.tgz",
@@ -367,29 +262,6 @@
"node": ">=6.9.0"
}
},
"node_modules/@babel/helper-validator-option": {
"version": "7.22.15",
"resolved": "https://registry.npmjs.org/@babel/helper-validator-option/-/helper-validator-option-7.22.15.tgz",
"integrity": "sha512-bMn7RmyFjY/mdECUbgn9eoSY4vqvacUnS9i9vGAGttgFWesO6B4CYWA7XlpbWgBt71iv/hfbPlynohStqnu5hA==",
"peer": true,
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/@babel/helpers": {
"version": "7.23.4",
"resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.23.4.tgz",
"integrity": "sha512-HfcMizYz10cr3h29VqyfGL6ZWIjTwWfvYBMsBVGwpcbhNGe3wQ1ZXZRPzZoAHhd9OqHadHqjQ89iVKINXnbzuw==",
"peer": true,
"dependencies": {
"@babel/template": "^7.22.15",
"@babel/traverse": "^7.23.4",
"@babel/types": "^7.23.4"
},
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/@babel/highlight": {
"version": "7.23.4",
"resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.23.4.tgz",
@@ -4064,6 +3936,7 @@
"version": "4.22.1",
"resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.22.1.tgz",
"integrity": "sha512-FEVc202+2iuClEhZhrWy6ZiAcRLvNMyYcxZ8raemul1DYVOVdFsbqckWLdsixQZCpJlwe77Z3UTalE7jsjnKfQ==",
"dev": true,
"funding": [
{
"type": "opencollective",
@@ -4262,6 +4135,7 @@
"version": "1.0.30001559",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001559.tgz",
"integrity": "sha512-cPiMKZgqgkg5LY3/ntGeLFUpi6tzddBNS58A4tnTgQw1zON7u2sZMU7SzOeVH4tj20++9ggL+V6FDOFMTaFFYA==",
"dev": true,
"funding": [
{
"type": "opencollective",
@@ -5631,7 +5505,8 @@
"node_modules/electron-to-chromium": {
"version": "1.4.572",
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.572.tgz",
"integrity": "sha512-RlFobl4D3ieetbnR+2EpxdzFl9h0RAJkPK3pfiwMug2nhBin2ZCsGIAJWdpNniLz43sgXam/CgipOmvTA+rUiA=="
"integrity": "sha512-RlFobl4D3ieetbnR+2EpxdzFl9h0RAJkPK3pfiwMug2nhBin2ZCsGIAJWdpNniLz43sgXam/CgipOmvTA+rUiA==",
"dev": true
},
"node_modules/elliptic": {
"version": "6.6.0",
@@ -5869,6 +5744,7 @@
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz",
"integrity": "sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==",
"dev": true,
"engines": {
"node": ">=6"
}
@@ -7094,15 +6970,6 @@
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/gensync": {
"version": "1.0.0-beta.2",
"resolved": "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.2.tgz",
"integrity": "sha512-3hN7NaskYvMDLQY55gnW3NQ+mesEAepTqlg+VEbj7zzqEMBVNhzcGYYeqFo/TlYz6eQiFcp1HcsCZO+nGgS8zg==",
"peer": true,
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/get-intrinsic": {
"version": "1.2.7",
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.7.tgz",
@@ -8518,6 +8385,7 @@
"version": "2.2.3",
"resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz",
"integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==",
"dev": true,
"bin": {
"json5": "lib/cli.js"
},
@@ -9256,15 +9124,6 @@
"tslib": "^2.0.3"
}
},
"node_modules/lru-cache": {
"version": "5.1.1",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz",
"integrity": "sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w==",
"peer": true,
"dependencies": {
"yallist": "^3.0.2"
}
},
"node_modules/map-obj": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/map-obj/-/map-obj-2.0.0.tgz",
@@ -9610,7 +9469,8 @@
"node_modules/node-releases": {
"version": "2.0.13",
"resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.13.tgz",
"integrity": "sha512-uYr7J37ae/ORWdZeQ1xxMJe3NtdmqMC/JZK+geofDrkLUApKRHPd18/TxtBOJ4A0/+uUIliorNrfYV6s1b02eQ=="
"integrity": "sha512-uYr7J37ae/ORWdZeQ1xxMJe3NtdmqMC/JZK+geofDrkLUApKRHPd18/TxtBOJ4A0/+uUIliorNrfYV6s1b02eQ==",
"dev": true
},
"node_modules/normalize-path": {
"version": "3.0.0",
@@ -10141,7 +10001,8 @@
"node_modules/picocolors": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.1.tgz",
"integrity": "sha512-anP1Z8qwhkbmu7MFP5iTt+wQKXgwzf7zTyGlcdzabySa9vd0Xt392U0rVmz9poOaBj0uHJKyyo9/upk0HrEQew=="
"integrity": "sha512-anP1Z8qwhkbmu7MFP5iTt+wQKXgwzf7zTyGlcdzabySa9vd0Xt392U0rVmz9poOaBj0uHJKyyo9/upk0HrEQew==",
"dev": true
},
"node_modules/picomatch": {
"version": "2.3.1",
@@ -11435,6 +11296,7 @@
"version": "6.3.1",
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz",
"integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==",
"dev": true,
"bin": {
"semver": "bin/semver.js"
}
@@ -12737,6 +12599,7 @@
"version": "5.5.4",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.4.tgz",
"integrity": "sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==",
"dev": true,
"license": "Apache-2.0",
"bin": {
"tsc": "bin/tsc",
@@ -12823,6 +12686,7 @@
"version": "1.0.13",
"resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.0.13.tgz",
"integrity": "sha512-xebP81SNcPuNpPP3uzeW1NYXxI3rxyJzF3pD6sH4jE7o/IX+WtSpwnVU+qIsDPyk0d3hmFQ7mjqc6AtV604hbg==",
"dev": true,
"funding": [
{
"type": "opencollective",
@@ -13515,12 +13379,6 @@
}
}
},
"node_modules/yallist": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz",
"integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==",
"peer": true
},
"node_modules/yaml": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/yaml/-/yaml-2.3.1.tgz",

View File

@@ -1,24 +1,33 @@
/* eslint-disable import/prefer-default-export */
import styled from 'styled-components';
// eslint-disable-next-line import/prefer-default-export
const Logo = styled('img')((props) => ({
maxHeight: 48,
maxWidth: 48,
paddingBlockStart: props.theme.space.xxl,
const ImgContainer = styled('div')({
display: 'flex',
justifyContent: 'center',
});
const Img = styled('img')((props) => ({
height: 48,
width: 48,
alignSelf: 'center',
objectFit: 'contain',
borderRadius: props.theme.radius(1),
}));
type Props = {
/**
* Any source that can be used as an image source.
*/
src?: string;
src?: string | null;
};
export function DappLogo({ src }: Props) {
if (!src) {
return null;
}
return <Logo src={src} alt="Dapp Logo" />;
return (
<ImgContainer>
<Img src={src} alt="Dapp Logo" />
</ImgContainer>
);
}

View File

@@ -1,3 +1,6 @@
import { permissions } from '@secretkeylabs/xverse-core';
import { useTranslation } from 'react-i18next';
import styled from 'styled-components';
/* eslint-disable import/prefer-default-export */
@@ -8,12 +11,29 @@ const Container = styled('div')((props) => ({
}));
type Props = {
url: ConstructorParameters<typeof URL>[0];
origin: string;
};
export function Host({ url }: Props) {
const parsedUrl = new URL(url);
const { host } = parsedUrl;
export function Host({ origin }: Props) {
const { t } = useTranslation('translation', { keyPrefix: 'AUTH_REQUEST_SCREEN' });
return <Container>{host}</Container>;
const { nameFromOrigin } = permissions.utils.originName;
const name = nameFromOrigin(origin);
const dappName = (() => {
// This means there was no name found for the origin, and the host is used
// as the name instead.
if (name === origin) {
const parsedUrl = new URL(origin);
return parsedUrl.host;
}
return name;
})();
return (
<Container>
{t('REQUEST_TOOLTIP')} {dappName}
</Container>
);
}

View File

@@ -56,3 +56,15 @@ export const RequestMessage = styled.p((props) => ({
wordWrap: 'break-word',
marginTop: props.theme.space.l,
}));
export const DappInfoContainer = styled('div')((props) => ({
display: 'flex',
flexDirection: 'column',
rowGap: props.theme.space.m,
}));
export const DappInfoTextContainer = styled('div')((props) => ({
display: 'flex',
flexDirection: 'column',
rowGap: props.theme.space.xxs,
}));

View File

@@ -23,11 +23,15 @@ import {
AddressBoxContainer,
Container,
ContentContainer,
DappInfoContainer,
DappInfoTextContainer,
PermissionDescriptionsContainer,
RequestMessage,
} from './index.styles';
import useSelectedAccount from '@hooks/useSelectedAccount';
import { getAppIconFromWebManifest, safePromise } from '@secretkeylabs/xverse-core';
import { useQuery } from '@tanstack/react-query';
import AddressPurposeBox from '../addressPurposeBox';
import * as Permissions from './permissions';
import { SelectAccountPrompt } from './selectAccount';
@@ -45,6 +49,17 @@ function ConnectionRequestInner({ data, context }: ConnectionRequestInnerProps)
}, []);
const handleAccept = useMakeHandleAccept({ context, data });
const { data: appIconSrc } = useQuery({
queryKey: ['appIcon', context.origin],
queryFn: async () => {
const [error, icon] = await safePromise(getAppIconFromWebManifest(context.origin));
if (error) return null;
return icon;
},
});
const AddressPurposeRow = useCallback(
(purpose: AddressPurpose) => {
if (purpose === AddressPurpose.Payment) {
@@ -88,14 +103,18 @@ function ConnectionRequestInner({ data, context }: ConnectionRequestInnerProps)
return (
<Container>
<ContentContainer>
<DappLogo />
<Title />
<Host url={context.origin} />
{(data as ConnectRequestMessage).params?.message && (
<RequestMessage>
{(data as ConnectRequestMessage).params?.message?.substring(0, 80)}
</RequestMessage>
)}
<DappInfoContainer>
<DappLogo src={appIconSrc} />
<DappInfoTextContainer>
<Title />
<Host origin={context.origin} />
{(data as ConnectRequestMessage).params?.message && (
<RequestMessage>
{(data as ConnectRequestMessage).params?.message?.substring(0, 80)}
</RequestMessage>
)}
</DappInfoTextContainer>
</DappInfoContainer>
<AccountSwitcherContainer>
<SelectAccountPrompt />
</AccountSwitcherContainer>

View File

@@ -146,11 +146,11 @@ export default function SwapScreen() {
const { data: fromRuneFloorPrice } = useRuneFloorPriceQuery(fromToken?.name ?? '');
useEffect(() => {
if (defaultFrom) {
if (defaultFrom && !fromToken) {
const token = coinsMasterList.find((coin) => coin.principal === defaultFrom);
setFromToken(token);
}
if (defaultTo) {
if (defaultTo && !toToken) {
const token = coinsMasterList.find((coin) => coin.principal === defaultTo);
setToToken(token);
}
@@ -216,8 +216,10 @@ export default function SwapScreen() {
setInputError('');
setAmount('');
setHasQuoteError(false);
const newFrom = toToken;
const newTo = fromToken;
setFromToken(newFrom);
setToToken(newTo);

View File

@@ -8,14 +8,21 @@ import {
} from '@secretkeylabs/xverse-core';
import BigNumber from 'bignumber.js';
const getFiatEquivalent = (
token: FungibleToken | undefined,
amount: BigNumber,
btcUsdRate: BigNumber,
runeFloorPrice?: BigNumber,
stxBtcRate?: BigNumber,
stxTokenFiatValue?: BigNumber,
) => {
const getFiatEquivalent = ({
token,
amount,
btcUsdRate,
runeFloorPrice,
stxBtcRate,
stxTokenFiatValue,
}: {
token: FungibleToken | undefined;
amount: BigNumber;
btcUsdRate: BigNumber;
runeFloorPrice?: BigNumber;
stxBtcRate?: BigNumber;
stxTokenFiatValue?: BigNumber;
}) => {
if (!token || amount.isZero()) {
return undefined;
}
@@ -65,17 +72,29 @@ const getSwapsMixpanelProperties = ({
const to = toToken?.principal === 'BTC' ? 'BTC' : toToken?.name ?? toToken?.ticker;
const fromTokenAmount = amount;
const fromTokenUsdValue = getFiatEquivalent(
fromToken,
new BigNumber(amount),
btcUsdRate,
fromRuneFloorPrice,
stxBtcRate,
fromStxTokenFiatValue,
);
const toTokenAmount = quote?.receiveAmount;
let rawFromTokenUsdValue;
let fromTokenUsdValue = getFiatEquivalent({
token: fromToken,
amount: new BigNumber(amount),
btcUsdRate,
runeFloorPrice: fromRuneFloorPrice,
stxBtcRate,
stxTokenFiatValue: fromStxTokenFiatValue,
});
// Derive fromTokenUsdValue from received STX amount
if (toToken?.principal === 'STX' && quote?.receiveAmount && stxBtcRate) {
rawFromTokenUsdValue = fromTokenUsdValue;
fromTokenUsdValue = getFiatEquivalent({
token: toToken,
amount: new BigNumber(quote.receiveAmount),
btcUsdRate,
stxBtcRate,
});
}
const fromPrincipal = fromToken?.protocol === 'stacks' ? fromToken?.principal : undefined;
const toPrincipal = toToken?.protocol === 'stacks' ? toToken?.principal : undefined;
@@ -89,6 +108,7 @@ const getSwapsMixpanelProperties = ({
...(fromTokenAmount ? { fromTokenAmount } : {}),
...{ fromTokenUsdValue: fromTokenUsdValue ?? 0 },
...(toTokenAmount ? { toTokenAmount } : {}),
...(rawFromTokenUsdValue ? { rawFromTokenUsdValue } : {}),
};
};

View File

@@ -330,7 +330,7 @@ export default function QuoteSummary({
<Callout
titleText={t('SWAP_SCREEN.BAD_QUOTE_WARNING_TITLE')}
bodyText={
quote.slippageSupported && BigNumber(toTokenFiatValue).isGreaterThan(0)
BigNumber(toTokenFiatValue).isGreaterThan(0)
? t('SWAP_SCREEN.BAD_QUOTE_WARNING_DESC', {
percentage: valueLossPercentage,
})

View File

@@ -1630,7 +1630,7 @@
"LIST_YOUR_RUNES": "List your Runes on a marketplace",
"SLIPPAGE_WARNING": "Your transaction may be frontrun and result in an unfavorable trade",
"BAD_QUOTE_WARNING_TITLE": "The quote you are receiving may result in significant value loss.",
"BAD_QUOTE_WARNING_DESC": "The minimum amount you will receive will result in a loss of over {{percentage}}% of your trades value. This is due to low liquidity in the pool, causing discrepancies in pricing. Please review the details carefully before proceeding with the swap.",
"BAD_QUOTE_WARNING_DESC": "The minimum amount you will receive will result in a loss of over {{percentage}}% of your trades value. This could be due to low liquidity in the pool or other provider issues. Please review the details carefully before proceeding with the swap.",
"UNKNOWN_QUOTE_VALUE_WARNING_DESC": "The market value of the token you will receive is unknown. Review details carefully before proceeding with the swap."
},
"SWAP_CONFIRM_SCREEN": {