Skip to content

Commit

Permalink
Merge pull request #1096 from rainlanguage/Replace-subgraph-types-wit…
Browse files Browse the repository at this point in the history
…h-js_api
  • Loading branch information
hardyjosh authored Dec 19, 2024
2 parents cdec7a5 + 7539b9a commit 5a51354
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 40 deletions.
9 changes: 8 additions & 1 deletion crates/common/src/types/order_detail_extended.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
use crate::meta::{TryDecodeRainlangSource, TryDecodeRainlangSourceError};
#[cfg(target_family = "wasm")]
use rain_orderbook_bindings::{impl_all_wasm_traits, wasm_traits::prelude::*};
use rain_orderbook_subgraph_client::types::common::Order;
use serde::{Deserialize, Serialize};
use typeshare::typeshare;

#[typeshare]
#[derive(Serialize, Deserialize, Clone, Debug)]
#[cfg_attr(target_family = "wasm", derive(Tsify))]
#[serde(rename_all = "camelCase")]
#[typeshare]
pub struct OrderDetailExtended {
pub order: Order,
pub rainlang: Option<String>,
Expand All @@ -26,3 +30,6 @@ impl TryFrom<Order> for OrderDetailExtended {
})
}
}

#[cfg(target_family = "wasm")]
impl_all_wasm_traits!(OrderDetailExtended);
9 changes: 8 additions & 1 deletion crates/subgraph/src/types/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ pub struct VaultBalanceChangeVault {
#[typeshare]
#[serde(rename_all = "camelCase")]
pub struct VaultBalanceChangeUnwrapped {
#[serde(rename = "__typename")]
pub __typename: String,
pub amount: BigInt,
pub new_vault_balance: BigInt,
Expand Down Expand Up @@ -233,6 +234,7 @@ pub enum VaultBalanceChange {
#[serde(rename_all = "camelCase")]
pub struct Deposit {
pub id: Bytes,
#[serde(rename = "__typename")]
pub __typename: String,
#[cfg_attr(target_family = "wasm", tsify(type = "SgBigInt"))]
pub amount: BigInt,
Expand All @@ -253,6 +255,7 @@ pub struct Deposit {
#[serde(rename_all = "camelCase")]
pub struct Withdrawal {
pub id: Bytes,
#[serde(rename = "__typename")]
pub __typename: String,
#[cfg_attr(target_family = "wasm", tsify(type = "SgBigInt"))]
pub amount: BigInt,
Expand All @@ -273,6 +276,7 @@ pub struct Withdrawal {
#[serde(rename_all = "camelCase")]
pub struct TradeVaultBalanceChange {
pub id: Bytes,
#[serde(rename = "__typename")]
pub __typename: String,
#[cfg_attr(target_family = "wasm", tsify(type = "SgBigInt"))]
pub amount: BigInt,
Expand All @@ -293,6 +297,7 @@ pub struct TradeVaultBalanceChange {
#[serde(rename_all = "camelCase")]
pub struct ClearBounty {
pub id: Bytes,
#[serde(rename = "__typename")]
pub __typename: String,
#[cfg_attr(target_family = "wasm", tsify(type = "SgBigInt"))]
pub amount: BigInt,
Expand Down Expand Up @@ -346,9 +351,11 @@ pub struct OrderStructPartialTrade {
pub struct Erc20 {
pub id: Bytes,
pub address: Bytes,
#[cfg_attr(target_family = "wasm", tsify(type = "string | undefined"))]
pub name: Option<String>,
#[cfg_attr(target_family = "wasm", tsify(type = "string | undefined"))]
pub symbol: Option<String>,
#[cfg_attr(target_family = "wasm", tsify(type = "SgBigInt"))]
#[cfg_attr(target_family = "wasm", tsify(type = "SgBigInt | undefined"))]
pub decimals: Option<BigInt>,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { render, screen } from '@testing-library/svelte';
import ButtonVaultLink from '../lib/components/ButtonVaultLink.svelte';
import * as navigation from '$app/navigation';
import { userEvent } from '@testing-library/user-event';
import type { Vault } from '../lib/typeshare/subgraphTypes';
import type { Vault } from '@rainlanguage/orderbook/js_api';

// Mock the $app/navigation module
vi.mock('$app/navigation', () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { render, screen, waitFor } from '@testing-library/svelte';
import { test, vi, type Mock } from 'vitest';
import { expect } from '../lib/test/matchers';
import { mockIPC } from '@tauri-apps/api/mocks';
import type { Trade } from '../lib/typeshare/subgraphTypes';
import type { Trade } from '@rainlanguage/orderbook/js_api';
import { formatUnits } from 'viem';
import OrderTradesListTable from '../lib/components/tables/OrderTradesListTable.svelte';
import { QueryClient } from '@tanstack/svelte-query';
Expand Down Expand Up @@ -34,7 +34,7 @@ const mockTradeOrdersList: Trade[] = [
}
},
id: '1',
typename: 'Withdraw',
__typename: 'Withdraw',
newVaultBalance: '0',
oldVaultBalance: '0',
timestamp: '0',
Expand Down Expand Up @@ -64,7 +64,7 @@ const mockTradeOrdersList: Trade[] = [
},
amount: '50',
id: '1',
typename: 'Withdraw',
__typename: 'Withdraw',
newVaultBalance: '0',
oldVaultBalance: '0',
timestamp: '0',
Expand Down Expand Up @@ -106,7 +106,7 @@ const mockTradeOrdersList: Trade[] = [
}
},
id: '1',
typename: 'Withdraw',
__typename: 'Withdraw',
newVaultBalance: '0',
oldVaultBalance: '0',
timestamp: '0',
Expand Down Expand Up @@ -136,7 +136,7 @@ const mockTradeOrdersList: Trade[] = [
},
amount: '50',
id: '1',
typename: 'Withdraw',
__typename: 'Withdraw',
newVaultBalance: '0',
oldVaultBalance: '0',
timestamp: '0',
Expand Down
4 changes: 2 additions & 2 deletions packages/ui-components/src/lib/__fixtures__/orderDetail.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { OrderDetailExtended } from '../typeshare/subgraphTypes';
import type { OrderDetailExtended } from '@rainlanguage/orderbook/js_api';

export const mockOrderDetailsExtended: OrderDetailExtended = {
order: {
Expand Down Expand Up @@ -63,7 +63,7 @@ export const mockOrderDetailsExtended: OrderDetailExtended = {
trades: []
},
rainlang: 'rainlang1'
};
} as unknown as OrderDetailExtended;

export const mockOrder = {
id: '0x9229dadc45c673afcbc393231d5ab0e15bb65719daa5d58bd85adfca3fd60d48',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { goto } from '$app/navigation';
import type { Vault } from '../typeshare/subgraphTypes';
import type { Vault } from '@rainlanguage/orderbook/js_api';
import { bigintStringToHex } from '../utils/hex';
import { Tooltip } from 'flowbite-svelte';
import { formatUnits } from 'viem';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Hash, { HashType } from '../Hash.svelte';
import { formatUnits } from 'viem';
import { BugOutline } from 'flowbite-svelte-icons';
import type { Trade } from '../../typeshare/subgraphTypes';
import type { Trade } from '@rainlanguage/orderbook/js_api';
import TableTimeFilters from '../charts/TableTimeFilters.svelte';
export let id: string;
Expand Down
1 change: 0 additions & 1 deletion packages/ui-components/src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export { default as IconWarning } from './components/IconWarning.svelte';
//Types
export type { AppStoresInterface } from './types/appStores.ts';
export type { ConfigSource, OrderbookConfigSource, OrderbookRef } from './typeshare/config';
export type { Vault } from './typeshare/subgraphTypes';

// Functions
export { createResolvableQuery, createResolvableInfiniteQuery } from './__mocks__/queries';
Expand Down
26 changes: 13 additions & 13 deletions packages/ui-components/src/lib/services/historicalOrderCharts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Trade } from '../typeshare/subgraphTypes';
import type { Trade } from '@rainlanguage/orderbook/js_api';
import type { UTCTimestamp } from 'lightweight-charts';
import { timestampSecondsToUTCTimestamp } from '../utils/time';
import { sortBy } from 'lodash';
Expand Down Expand Up @@ -85,7 +85,7 @@ if (import.meta.vitest) {
}
},
id: '1',
typename: 'Withdraw',
__typename: 'Withdraw',
newVaultBalance: '0',
oldVaultBalance: '0',
timestamp: '0',
Expand Down Expand Up @@ -115,7 +115,7 @@ if (import.meta.vitest) {
},
amount: '50',
id: '1',
typename: 'Withdraw',
__typename: 'Withdraw',
newVaultBalance: '0',
oldVaultBalance: '0',
timestamp: '0',
Expand Down Expand Up @@ -157,7 +157,7 @@ if (import.meta.vitest) {
}
},
id: '1',
typename: 'Withdraw',
__typename: 'Withdraw',
newVaultBalance: '0',
oldVaultBalance: '0',
timestamp: '0',
Expand Down Expand Up @@ -187,7 +187,7 @@ if (import.meta.vitest) {
},
amount: '50',
id: '1',
typename: 'Withdraw',
__typename: 'Withdraw',
newVaultBalance: '0',
oldVaultBalance: '0',
timestamp: '0',
Expand Down Expand Up @@ -229,7 +229,7 @@ if (import.meta.vitest) {
}
},
id: '1',
typename: 'Withdraw',
__typename: 'Withdraw',
newVaultBalance: '0',
oldVaultBalance: '0',
timestamp: '0',
Expand Down Expand Up @@ -259,7 +259,7 @@ if (import.meta.vitest) {
},
amount: '50',
id: '1',
typename: 'Withdraw',
__typename: 'Withdraw',
newVaultBalance: '0',
oldVaultBalance: '0',
timestamp: '0',
Expand Down Expand Up @@ -321,7 +321,7 @@ if (import.meta.vitest) {
}
},
id: '1',
typename: 'Withdraw',
__typename: 'Withdraw',
newVaultBalance: '0',
oldVaultBalance: '0',
timestamp: '0',
Expand Down Expand Up @@ -351,7 +351,7 @@ if (import.meta.vitest) {
},
amount: '50',
id: '1',
typename: 'Withdraw',
__typename: 'Withdraw',
newVaultBalance: '0',
oldVaultBalance: '0',
timestamp: '0',
Expand Down Expand Up @@ -393,7 +393,7 @@ if (import.meta.vitest) {
}
},
id: '1',
typename: 'Withdraw',
__typename: 'Withdraw',
newVaultBalance: '0',
oldVaultBalance: '0',
timestamp: '0',
Expand Down Expand Up @@ -423,7 +423,7 @@ if (import.meta.vitest) {
},
amount: '50',
id: '1',
typename: 'Withdraw',
__typename: 'Withdraw',
newVaultBalance: '0',
oldVaultBalance: '0',
timestamp: '0',
Expand Down Expand Up @@ -465,7 +465,7 @@ if (import.meta.vitest) {
}
},
id: '1',
typename: 'Withdraw',
__typename: 'Withdraw',
newVaultBalance: '0',
oldVaultBalance: '0',
timestamp: '0',
Expand Down Expand Up @@ -495,7 +495,7 @@ if (import.meta.vitest) {
},
amount: '50',
id: '1',
typename: 'Withdraw',
__typename: 'Withdraw',
newVaultBalance: '0',
oldVaultBalance: '0',
timestamp: '0',
Expand Down
4 changes: 2 additions & 2 deletions packages/ui-components/src/lib/utils/vault.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Vault } from '../typeshare/subgraphTypes';
import type { Vault } from '@rainlanguage/orderbook/js_api';
import { formatUnits } from 'viem';

export const vaultBalanceDisplay = (vault: Vault) => {
Expand All @@ -25,7 +25,7 @@ if (import.meta.vitest) {
orderbook: {
id: '0x00'
}
} as Vault;
} as unknown as Vault;

expect(vaultBalanceDisplay(vault)).toEqual('1');

Expand Down
6 changes: 3 additions & 3 deletions tauri-app/src/lib/components/charts/VaultBalanceChart.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ vi.mock('lightweight-charts', async () => {

const mockVaultBalanceChangeUnwrappeds: VaultBalanceChangeUnwrapped[] = [
{
typename: 'Withdrawal',
__typename: 'Withdrawal',
amount: '1000',
oldVaultBalance: '5000',
newVaultBalance: '4000',
Expand All @@ -75,7 +75,7 @@ const mockVaultBalanceChangeUnwrappeds: VaultBalanceChangeUnwrapped[] = [
},
},
{
typename: 'TradeVaultBalanceChangeUnwrapped',
__typename: 'TradeVaultBalanceChangeUnwrapped',
amount: '1500',
oldVaultBalance: '4000',
newVaultBalance: '2500',
Expand All @@ -102,7 +102,7 @@ const mockVaultBalanceChangeUnwrappeds: VaultBalanceChangeUnwrapped[] = [
},
},
{
typename: 'Deposit',
__typename: 'Deposit',
amount: '2000',
oldVaultBalance: '2500',
newVaultBalance: '4500',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
{item.vault.token.symbol}
</TableBodyCell>
<TableBodyCell tdClass="break-word p-0 text-left" data-testid="vaultBalanceChangesTableType">
{item.typename}
{item.__typename}
</TableBodyCell>
</svelte:fragment>
</TanstackAppTable>
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ test('renders the vault list table with correct data', async () => {

const mockVaultBalanceChanges: VaultBalanceChangeUnwrapped[] = [
{
typename: 'Withdrawal',
__typename: 'Withdrawal',
amount: '1000',
oldVaultBalance: '5000',
newVaultBalance: '4000',
Expand All @@ -56,7 +56,7 @@ test('renders the vault list table with correct data', async () => {
},
},
{
typename: 'TradeVaultBalanceChange',
__typename: 'TradeVaultBalanceChange',
amount: '1500',
oldVaultBalance: '4000',
newVaultBalance: '2500',
Expand All @@ -83,7 +83,7 @@ test('renders the vault list table with correct data', async () => {
},
},
{
typename: 'Deposit',
__typename: 'Deposit',
amount: '2000',
oldVaultBalance: '2500',
newVaultBalance: '4500',
Expand Down Expand Up @@ -133,7 +133,7 @@ test('it shows the correct data in the table', async () => {

const mockVaultBalanceChanges: VaultBalanceChangeUnwrapped[] = [
{
typename: 'Withdrawal',
__typename: 'Withdrawal',
amount: '1000',
oldVaultBalance: '5000',
newVaultBalance: '4000',
Expand Down
6 changes: 3 additions & 3 deletions tauri-app/src/lib/queries/vaultBalanceChangesList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ if (import.meta.vitest) {
it('uses the vault_balance_changes_list command correctly', async () => {
const mockVaultBalanceChanges: VaultBalanceChangeUnwrapped[] = [
{
typename: 'Withdrawal',
__typename: 'Withdrawal',
amount: '1000',
oldVaultBalance: '5000',
newVaultBalance: '4000',
Expand All @@ -63,7 +63,7 @@ if (import.meta.vitest) {
},
},
{
typename: 'TradeVaultBalanceChange',
__typename: 'TradeVaultBalanceChange',
amount: '1500',
oldVaultBalance: '4000',
newVaultBalance: '2500',
Expand All @@ -90,7 +90,7 @@ if (import.meta.vitest) {
},
},
{
typename: 'Deposit',
__typename: 'Deposit',
amount: '2000',
oldVaultBalance: '2500',
newVaultBalance: '4500',
Expand Down
Loading

0 comments on commit 5a51354

Please sign in to comment.