Skip to content

Commit

Permalink
Merge branch 'main' into deps-react-native-datetimepicker-slider
Browse files Browse the repository at this point in the history
  • Loading branch information
legobeat authored Aug 20, 2024
2 parents f476741 + 5a31f91 commit 07044c9
Show file tree
Hide file tree
Showing 17 changed files with 96 additions and 181 deletions.
8 changes: 4 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,21 @@ GEM
netrc (0.11.0)
nkf (0.2.0)
public_suffix (4.0.7)
rexml (3.2.8)
strscan (>= 3.0.9)
rexml (3.3.3)
strscan
ruby-macho (2.5.1)
strscan (3.1.0)
typhoeus (1.4.1)
ethon (>= 0.9.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
xcodeproj (1.24.0)
xcodeproj (1.25.0)
CFPropertyList (>= 2.3.3, < 4.0)
atomos (~> 0.1.3)
claide (>= 1.0.2, < 2.0)
colored2 (~> 3.1)
nanaimo (~> 0.3.0)
rexml (~> 3.2.4)
rexml (>= 3.3.2, < 4.0)

PLATFORMS
arm64-darwin-22
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,35 @@ import { RampType } from '../../../../../reducers/fiatOrders/types';
const mockedRampNetworksValues: AggregatorNetwork[] = [
{
active: true,
chainId: 1,
chainId: '1',
chainName: 'Ethereum Mainnet',
nativeTokenSupported: true,
shortName: 'Ethereum',
},
{
active: true,
chainId: 59144,
chainId: '59144',
chainName: 'Linea Mainnet',
nativeTokenSupported: true,
shortName: 'Linea',
},
{
active: true,
chainId: 25,
chainId: '25',
chainName: 'Cronos Mainnet',
nativeTokenSupported: true,
shortName: 'Cronos',
},
{
active: true,
chainId: 137,
chainId: '137',
chainName: 'Polygon Mainnet',
nativeTokenSupported: true,
shortName: 'Polygon',
},
{
active: false,
chainId: 56,
chainId: '56',
chainName: 'BNB Smart Chain',
nativeTokenSupported: false,
shortName: 'BNB Smart Chain',
Expand All @@ -66,7 +66,7 @@ const mockedNetworksDetails = [
},
];

function render(Component: React.ComponentType, chainId?: string) {
function render(Component: React.ComponentType, chainId?: `0x${string}`) {
return renderScreen(
Component,
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function NetworkSwitcher() {
const error = errorFetchingNetworks || errorFetchingNetworksDetail;
const rampNetworksDetails = useMemo(() => {
const activeNetworkDetails: Network[] = [];
// TODO(ramp, chainId-string): filter supportedNetworks by EVM compatible chains (chainId are strings of decimal numbers)
// TODO(ramp, btc): filter supportedNetworks by EVM compatible chains (chainId are strings of decimal numbers)
supportedNetworks.forEach(({ chainId: supportedChainId, active }) => {
let rampSupportedNetworkChainIdAsHex: `0x${string}`;
try {
Expand Down
6 changes: 3 additions & 3 deletions app/components/UI/Ramp/Views/Quotes/Quotes.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const mockQuotesData = [
idv2: '/currencies/crypto/1/0x0000000000000000000000000000000000000000',
network: {
active: true,
chainId: 1,
chainId: '1',
chainName: 'Ethereum Mainnet',
shortName: 'Ethereum',
},
Expand Down Expand Up @@ -89,7 +89,7 @@ export const mockQuotesData = [
idv2: '/currencies/crypto/1/0x0000000000000000000000000000000000000000',
network: {
active: true,
chainId: 1,
chainId: '1',
chainName: 'Ethereum Mainnet',
shortName: 'Ethereum',
},
Expand Down Expand Up @@ -172,7 +172,7 @@ export const mockQuotesData = [
idv2: '/currencies/crypto/1/0x0000000000000000000000000000000000000000',
network: {
active: true,
chainId: 1,
chainId: '1',
chainName: 'Ethereum Mainnet',
shortName: 'Ethereum',
},
Expand Down
16 changes: 16 additions & 0 deletions app/components/UI/Ramp/Views/Quotes/Quotes.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ describe('Quotes', () => {
[
"ONRAMP_PROVIDER_SELECTED",
{
"amount": 50,
"chain_id_destination": "1",
"crypto_out": 0.0162,
"currency_destination": "ETH",
Expand Down Expand Up @@ -368,6 +369,7 @@ describe('Quotes', () => {
[
"OFFRAMP_PROVIDER_SELECTED",
{
"amount": 50,
"chain_id_source": "1",
"currency_destination": "USD",
"currency_source": "ETH",
Expand Down Expand Up @@ -402,6 +404,7 @@ describe('Quotes', () => {
[
"ONRAMP_PROVIDER_SELECTED",
{
"amount": 50,
"chain_id_destination": "1",
"crypto_out": 0.0162,
"currency_destination": "ETH",
Expand Down Expand Up @@ -431,6 +434,7 @@ describe('Quotes', () => {
[
"OFFRAMP_PROVIDER_SELECTED",
{
"amount": 50,
"chain_id_source": "1",
"currency_destination": "USD",
"currency_source": "ETH",
Expand Down Expand Up @@ -547,6 +551,12 @@ describe('Quotes', () => {
"Banxa (Staging)",
"MoonPay (Staging)",
],
"quotes_amount_first": 0.017142,
"quotes_amount_last": 0.0162,
"quotes_amount_list": [
0.017142,
0.0162,
],
"refresh_count": 1,
"results_count": 2,
},
Expand Down Expand Up @@ -600,6 +610,12 @@ describe('Quotes', () => {
"Banxa (Staging)",
"MoonPay (Staging)",
],
"quotes_amount_first": 0.017142,
"quotes_amount_last": 0.0162,
"quotes_amount_list": [
0.017142,
0.0162,
],
"refresh_count": 1,
"results_count": 2,
},
Expand Down
30 changes: 20 additions & 10 deletions app/components/UI/Ramp/Views/Quotes/Quotes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ function Quotes() {
processing_fee: quote.providerFee ?? 0,
exchange_rate:
((quote.amountIn ?? 0) - totalFee) / (quote.amountOut ?? 0),
amount: params.amount,
};

if (isBuy) {
Expand Down Expand Up @@ -500,6 +501,22 @@ function Quotes() {
},
);

const averageOut = totals.amountOut / quotesWithoutError.length;
const providerList = quotesWithoutError.map(
({ provider }) => provider.name,
);
const providerFirst = quotesWithoutError[0]?.provider?.name;
const providerLast =
quotesWithoutError.length > 1
? quotesWithoutError[quotesWithoutError.length - 1]?.provider?.name
: undefined;
const amountList = quotesWithoutError.map(({ amountOut }) => amountOut);
const amountFirst = quotesWithoutError[0]?.amountOut;
const amountLast =
quotesWithoutError.length > 1
? quotesWithoutError[quotesWithoutError.length - 1]?.amountOut
: undefined;

const payload = {
amount: params.amount,
payment_method_id: selectedPaymentMethodId as string,
Expand All @@ -511,18 +528,11 @@ function Quotes() {
totals.totalProcessingFee / quotesWithoutError.length,
average_total_fee_of_amount:
totals.feeAmountRatio / quotesWithoutError.length,
quotes_amount_list: amountList as number[],
quotes_amount_first: amountFirst as number,
quotes_amount_last: amountLast as number,
};

const averageOut = totals.amountOut / quotesWithoutError.length;
const providerList = quotesWithoutError.map(
({ provider }) => provider.name,
);
const providerFirst = quotesWithoutError[0]?.provider?.name;
const providerLast =
quotesWithoutError.length > 1
? quotesWithoutError[quotesWithoutError.length - 1]?.provider?.name
: undefined;

if (isBuy) {
trackEvent('ONRAMP_QUOTES_RECEIVED', {
...payload,
Expand Down
3 changes: 1 addition & 2 deletions app/components/UI/Ramp/hooks/useCryptoCurrencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ export default function useCryptoCurrencies() {
sdkCryptoCurrencies
) {
const filteredTokens = sdkCryptoCurrencies.filter(
// TODO(ramp, chainId-string): remove once chainId is a string
(token) => `${token.network?.chainId}` === selectedChainId,
(token) => token.network?.chainId === selectedChainId,
);
return filteredTokens;
}
Expand Down
9 changes: 3 additions & 6 deletions app/components/UI/Ramp/hooks/useHandleSuccessfulOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ function useHandleSuccessfulOrder() {
if (!token) return;

const { address, symbol, decimals, network, name } = token;
// TODO(ramp, chainId-string): remove once chainId is a string
const chainId = `${network?.chainId}`;
const chainId = network?.chainId;

if (chainId !== selectedChainId || address === NATIVE_ADDRESS) {
return;
Expand All @@ -43,10 +42,8 @@ function useHandleSuccessfulOrder() {
const { TokensController } = Engine.context;

if (
// TODO: Replace "any" with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
!TokensController.state.tokens.includes((t: any) =>
toLowerCaseEquals(t.address, address),
!TokensController.state.tokens.find((stateToken) =>
toLowerCaseEquals(stateToken.address, address),
)
) {
await TokensController.addToken({ address, symbol, decimals, name });
Expand Down
3 changes: 1 addition & 2 deletions app/components/UI/Ramp/hooks/usePaymentMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ function usePaymentMethods() {
if (
cryptoCurrencies?.some(
(cryptoCurrency) =>
// TODO(ramp, chainId-string): remove once chainId is a string
`${cryptoCurrency.network.chainId}` === selectedChainId,
cryptoCurrency.network.chainId === selectedChainId,
)
) {
allowed.push(method.id);
Expand Down
2 changes: 1 addition & 1 deletion app/components/UI/Ramp/orderProcessor/aggregator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ describe('aggregatorOrderToFiatOrder', () => {
fiatAmount: 123,
cryptoCurrency: {
network: {
chainId: 1,
chainId: '1',
},
},
status: 'COMPLETED',
Expand Down
4 changes: 1 addition & 3 deletions app/components/UI/Ramp/orderProcessor/aggregator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ export const aggregatorOrderToFiatOrder = (aggregatorOrder: Order) => ({
currencySymbol: aggregatorOrder.fiatCurrency?.denomSymbol || '',
cryptocurrency: aggregatorOrder.cryptoCurrency?.symbol || '',
network:
aggregatorOrder.network ||
// TODO(ramp, chainId-string): remove once chainId is a string
`${aggregatorOrder.cryptoCurrency?.network?.chainId}`,
aggregatorOrder.network || aggregatorOrder.cryptoCurrency?.network?.chainId,
state: aggregatorOrderStateToFiatOrderState(aggregatorOrder.status),
account: aggregatorOrder.walletAddress,
txHash: aggregatorOrder.txHash,
Expand Down
4 changes: 4 additions & 0 deletions app/components/UI/Ramp/types/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ interface RampQuotesReceived {
average_gas_fee: number;
average_processing_fee: number;
average_total_fee_of_amount: number;
quotes_amount_list: number[];
quotes_amount_first: number;
quotes_amount_last?: number;
}

interface OnRampQuotesReceived extends RampQuotesReceived {
Expand Down Expand Up @@ -120,6 +123,7 @@ interface RampProviderSelected {
gas_fee: number;
processing_fee: number;
exchange_rate: number;
amount: number | string;
}

interface OnRampProviderSelected extends RampProviderSelected {
Expand Down
Loading

0 comments on commit 07044c9

Please sign in to comment.