Skip to content

Commit

Permalink
Lightning start + Fix UI and hooks launchpad + redeploy launchpad (#48)
Browse files Browse the repository at this point in the history
* add lightning view + polyfills

* sidebar mainstack fix

* fix hook buy and sell + redeploy launchpad

* fix user card in feed to not appear

* add comment in used input for calculation of buy/sell

* fix typo
  • Loading branch information
MSghais authored Aug 22, 2024
1 parent de78fee commit 2ce3030
Show file tree
Hide file tree
Showing 23 changed files with 512 additions and 116 deletions.
13 changes: 13 additions & 0 deletions apps/mobile/applyGlobalPolyfills.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

const TextEncodingPolyfill = require("text-encoding");
import "react-native-url-polyfill/auto";
import "react-native-get-random-values";

const applyGlobalPolyfills = () => {
Object.assign(global, {
TextEncoder: TextEncodingPolyfill.TextEncoder,
TextDecoder: TextEncodingPolyfill.TextDecoder,
});
};

applyGlobalPolyfills();
8 changes: 7 additions & 1 deletion apps/mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,13 @@
"starknet": "6.9.0",
"starknetkit": "^1.1.9",
"zustand": "^4.5.2",
"common":"workspace:*"
"common":"workspace:*",
"@getalby/lightning-tools": "^5.0.3",
"@getalby/bitcoin-connect-react": "^3.5.3",
"@getalby/sdk": "^3.6.1",
"react-native-webview-crypto": "^0.0.25",
"text-encoding": "^0.7.0",
"@webbtc/webln-types": "^2.1.0"
},
"devDependencies": {
"@babel/core": "^7.20.0",
Expand Down
8 changes: 6 additions & 2 deletions apps/mobile/src/app/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {Profile} from '../screens/Profile';
import {Search} from '../screens/Search';
import {Settings} from '../screens/Settings';
import {Tips} from '../screens/Tips';
import {LightningNetworkScreen} from '../screens/Lightning';
import {ThemedStyleSheet} from '../styles';
import {AuthStackParams, HomeBottomStackParams, MainStackParams, RootStackParams} from '../types';
import {retrievePublicKey} from '../utils/storage';
Expand Down Expand Up @@ -193,7 +194,7 @@ const AuthNavigator: React.FC = () => {
overlayColor: isDesktop ? 'transparent' : theme.theme.colors.background, // Make sure overlay settings are correct
// swipeEdgeWidth: 0
drawerStyle: {
width: '25%', // Adjust width or other styling as necessary
width: '20%', // Adjust width or other styling as necessary
},
})}
>
Expand Down Expand Up @@ -230,7 +231,9 @@ const MainNavigator: React.FC = () => {
overlayColor: isDesktop ? 'transparent' : theme.theme.colors.background, // Make sure overlay settings are correct
// swipeEdgeWidth: 0
drawerStyle: {
width: 200, // Adjust width or other styling as necessary
// maxWidth:270,
// width: '15%', // Adjust width or other styling as necessary
width: 250, // Adjust width or other styling as necessary
},
})}
>
Expand All @@ -255,6 +258,7 @@ const MainNavigator: React.FC = () => {
<DrawerStack.Screen name="LaunchDetail" component={LaunchDetail} />
<DrawerStack.Screen name="Auth" component={AuthNavigator} />
<DrawerStack.Screen name="Login" component={Login} />
<DrawerStack.Screen name="Lightning" component={LightningNetworkScreen} />
</DrawerStack.Navigator>
);
};
Expand Down
36 changes: 19 additions & 17 deletions apps/mobile/src/hooks/launchpad/useBuyCoinByQuoteAmount.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import {useNetwork} from '@starknet-react/core';
import { useNetwork } from '@starknet-react/core';
// import { LAUNCHPAD_ADDRESS} from '../../constants/contracts';
import {LAUNCHPAD_ADDRESS} from 'common';
import {AccountInterface, CallData, constants, RpcProvider} from 'starknet';
import { LAUNCHPAD_ADDRESS } from 'common';
import { AccountInterface, CallData, constants, RpcProvider } from 'starknet';

import {TokenQuoteBuyKeys} from '../../types/keys';
import {feltToAddress, formatFloatToUint256} from '../../utils/format';
import {prepareAndConnectContract} from './useDataCoins';
import { TokenQuoteBuyKeys } from '../../types/keys';
import { feltToAddress, formatFloatToUint256 } from '../../utils/format';
import { prepareAndConnectContract , prepareTokenAndConnectContract} from '../../utils/starknet';

export const useBuyCoinByQuoteAmount = () => {
const chain = useNetwork();
const chainId = chain?.chain?.id;
const provider = new RpcProvider({nodeUrl: process.env.EXPO_PUBLIC_PROVIDER_URL});
const provider = new RpcProvider({ nodeUrl: process.env.EXPO_PUBLIC_PROVIDER_URL });
const handleBuyCoins = async (
account: AccountInterface,
coin_address: string,
Expand All @@ -24,15 +24,17 @@ export const useBuyCoinByQuoteAmount = () => {
contractAddress ?? LAUNCHPAD_ADDRESS[constants.StarknetChainId.SN_SEPOLIA];
console.log('addressContract', addressContract);
console.log('read asset');
const asset = await prepareAndConnectContract(
provider,
feltToAddress(BigInt(tokenQuote?.token_address)),
// tokenQuote?.token_address?.toString(),
account,
);
console.log('read launchpad_contract');
console.log(' feltToAddress(BigInt(tokenQuote?.token_address)', feltToAddress(BigInt(tokenQuote?.token_address)));
// const asset = await prepareAndConnectContract(
// provider,
// feltToAddress(BigInt(tokenQuote?.token_address)),
// // tokenQuote?.token_address?.toString(),
// account,
// );
// console.log('read launchpad_contract');

const launchpad_contract = await prepareAndConnectContract(provider, addressContract);
const quote_address_token=feltToAddress(BigInt(tokenQuote?.token_address));
// const launchpad_contract = await prepareAndConnectContract(provider, addressContract);
// const launchpad_contract = await prepareAndConnectContract(provider, addressContract, account);

console.log('amount', amount);
Expand All @@ -47,7 +49,7 @@ export const useBuyCoinByQuoteAmount = () => {
console.log('buyCoinParams', buyCoinParams);

const approveCall = {
contractAddress: asset?.address,
contractAddress: quote_address_token,
entrypoint: 'approve',
calldata: CallData.compile({
address: addressContract,
Expand All @@ -69,5 +71,5 @@ export const useBuyCoinByQuoteAmount = () => {
const wait_tx = await account?.waitForTransaction(tx?.transaction_hash);
};

return {handleBuyCoins};
return { handleBuyCoins };
};
11 changes: 7 additions & 4 deletions apps/mobile/src/hooks/launchpad/useDataCoins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {LAUNCHPAD_ADDRESS} from 'common';
import {AccountInterface, constants, Contract, ProviderInterface, RpcProvider} from 'starknet';

import {CHAIN_ID} from '../../constants/env';


/** @TODO determine paymaster master specs to send the TX */
export const prepareAndConnectContract = async (
provider: ProviderInterface,
Expand All @@ -16,15 +18,16 @@ export const prepareAndConnectContract = async (

const {abi: testAbi} = await provider.getClassAt(contractAddress);
if (testAbi === undefined) {
console.log("no abi")
throw new Error('no abi.');
}
const contract = new Contract(testAbi, contractAddress, provider);
console.log('contract', contract);

// Connect account with the contract
if (account) {
contract.connect(account);
}
// // Connect account with the contract
// if (account) {
// contract.connect(account);
// }
return contract;
};

Expand Down
3 changes: 1 addition & 2 deletions apps/mobile/src/hooks/launchpad/useSellCoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export const useSellCoin = () => {
const chain = useNetwork();
const rpcProvider = useProvider();
const chainId = chain?.chain?.id;
// const provider = rpcProvider?.provider ?? new RpcProvider();
const provider = rpcProvider?.provider ?? new RpcProvider();

const handleSellCoins = async (
Expand All @@ -30,7 +29,7 @@ export const useSellCoin = () => {
// );

let amountUint256 = formatFloatToUint256(amount);
amountUint256 = uint256.bnToUint256(BigInt('0x' + amount));
// amountUint256 = uint256.bnToUint256(BigInt('0x' + amount));

const sellKeysParams = {
user_address, // token address
Expand Down
2 changes: 1 addition & 1 deletion apps/mobile/src/modules/Layout/auth-sidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const AuthSidebar = ({navigation}: SidebarInterface) => {

<View style={styles.container}>
<Text style={styles.textItem}>Connect or create an Account</Text>
<Text style={styles.textItem}>Acces the AFK app</Text>
<Text style={styles.textItem}>Access the AFK app</Text>
</View>

<View style={styles.container}>
Expand Down
17 changes: 13 additions & 4 deletions apps/mobile/src/modules/Layout/sidebar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// import { useAuth } from '../../../store/auth';
import {useAuth, useNostrContext} from 'afk_nostr_sdk';
import React, {useEffect} from 'react';
import React, {useEffect, useMemo} from 'react';
import {Pressable, Text, View} from 'react-native';

import {Icon} from '../../../components/Icon';
import {useStyles, useTheme} from '../../../hooks';
import {useStyles, useTheme, useWindowDimensions} from '../../../hooks';
import stylesheet from './styles';

interface SidebarInterface {
Expand Down Expand Up @@ -49,6 +49,15 @@ const Sidebar = ({navigation}: SidebarInterface) => {
return unsubscribe;
}, [navigation]);

const dimensions = useWindowDimensions();
const isDesktop = useMemo(() => {
return dimensions.width >= 1024;
}, [dimensions]); // Adjust based on your breakpoint for desktop

// if(!isDesktop) {
// return;
// }

return (
<View style={styles.sidebar}>
<Text style={styles.sidebarText}>AFK</Text>
Expand Down Expand Up @@ -90,8 +99,8 @@ const Sidebar = ({navigation}: SidebarInterface) => {
</Pressable>

<Pressable onPress={handleDefiScreen} style={styles.item}>
<Icon name="CoinIcon" size={24} />
<Text style={styles.textItem}>Onramp & DeFI</Text>
<Icon name="CoinIcon" size={24} style={{backgroundColor: theme.theme.colors.background}} />
<Text style={styles.textItem}>DeFi</Text>
</Pressable>

{publicKey && (
Expand Down
Loading

0 comments on commit 2ce3030

Please sign in to comment.