Skip to content

Commit

Permalink
[Wallet]: Add swapPageForm (#14068)
Browse files Browse the repository at this point in the history
## Description 

- Wire SwapPageForm
Flag https://app.growthbook.io/features/wallet-fee-address


![defi-swap](https://github.com/MystenLabs/sui/assets/127577476/a956dcf5-2505-4fce-8d7d-a6e85a202f2d)


## Test Plan 

How did you test the new or updated feature?

---
If your changes are not user-facing and not a breaking change, you can
skip the following section. Otherwise, please indicate what changed, and
then add to the Release Notes section as highlighted during the release
process.

### Type of Change (Check all that apply)

- [ ] protocol change
- [ ] user-visible impact
- [ ] breaking change for a client SDKs
- [ ] breaking change for FNs (FN binary must upgrade)
- [ ] breaking change for validators or node operators (must upgrade
binaries)
- [ ] breaking change for on-chain data layout
- [ ] necessitate either a data wipe or data migration

### Release notes

---------

Co-authored-by: mamos-mysten <122397493+mamos-mysten@users.noreply.github.com>
  • Loading branch information
plam-ml and mamos-mysten authored Oct 24, 2023
1 parent 9e9b57b commit 7d997ae
Show file tree
Hide file tree
Showing 19 changed files with 1,525 additions and 161 deletions.
58 changes: 58 additions & 0 deletions apps/wallet/src/shared/deepBook/context.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
import { useActiveAccount } from '_app/hooks/useActiveAccount';
import { useGetOwnedObjects } from '@mysten/core';
import { useSuiClient } from '@mysten/dapp-kit';
import { DeepBookClient } from '@mysten/deepbook';
import { createContext, useContext, useMemo, type ReactNode } from 'react';

type DeepBookContextProps = {
client: DeepBookClient;
accountCapId: string;
};

const DeepBookContext = createContext<DeepBookContextProps | null>(null);

interface DeepBookContextProviderProps {
children: ReactNode;
}

export function useDeepBookContext() {
const context = useContext(DeepBookContext);
if (!context) {
throw new Error('useDeepBookContext must be used within a DeepBookContextProvider');
}
return context;
}

export function DeepBookContextProvider({ children }: DeepBookContextProviderProps) {
const suiClient = useSuiClient();
const activeAccount = useActiveAccount();
const activeAccountAddress = activeAccount?.address;

const { data } = useGetOwnedObjects(
activeAccountAddress,
{
MatchAll: [{ StructType: '0xdee9::custodian_v2::AccountCap' }],
},
1,
);

const objectContent = data?.pages?.[0]?.data?.[0]?.data?.content;
const objectFields = objectContent?.dataType === 'moveObject' ? objectContent?.fields : null;

const accountCapId = (objectFields as Record<string, string | number | object>)?.owner as string;

const deepBookClient = useMemo(() => {
return new DeepBookClient(suiClient, accountCapId);
}, [accountCapId, suiClient]);

const contextValue = useMemo(() => {
return {
client: deepBookClient,
accountCapId,
};
}, [accountCapId, deepBookClient]);

return <DeepBookContext.Provider value={contextValue}>{children}</DeepBookContext.Provider>;
}
1 change: 1 addition & 0 deletions apps/wallet/src/shared/experimentation/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export enum FEATURES {
WALLET_APPS_BANNER_CONFIG = 'wallet-apps-banner-config',
WALLET_INTERSTITIAL_CONFIG = 'wallet-interstitial-config',
WALLET_DEFI = 'wallet-defi',
WALLET_FEE_ADDRESS = 'wallet-fee-address',
}

export function setAttributes(network?: { apiEnv: API_ENV; customRPC?: string | null }) {
Expand Down
2 changes: 2 additions & 0 deletions apps/wallet/src/ui/app/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export { useGetTxnRecipientAddress } from './useGetTxnRecipientAddress';
export { useQueryTransactionsByAddress } from './useQueryTransactionsByAddress';
export { useGetTransferAmount } from './useGetTransferAmount';
export { useOwnedNFT } from './useOwnedNFT';
export { useSortedCoinsByCategories } from './useSortedCoinsByCategories';
export * from './useDeepBook';
export * from './useTransactionData';
export * from './useActiveAddress';
export * from './useGetAllCoins';
Expand Down
Loading

1 comment on commit 7d997ae

@vercel
Copy link

@vercel vercel bot commented on 7d997ae Oct 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.