Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge feature/transfer-all into develop #137

Merged
merged 6 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/app/api/_data/blk-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import TokenPriceFeedsAbi from './_abis/TokenPriceFeedsAbi.json'

// ---------------------------------------------------------------------------------------------

export async function transferAll(walletTo: string): Promise<boolean> {
export async function transferAll(channelUserId: string, walletTo: string): Promise<boolean> {
try {
// TODO:
// const data = { wallet: walletTo }
// const response = await axios.post(`${BACKEND_API_URL}/transferall`, data)
// const data = { channel_user_id: channelUserId, dst_address: walletTo }
// const response = await axios.post(`${BACKEND_API_URL}/withdraw_funds`, data)
return true
} catch (error) {
console.error('Error transfering all funds:', error)
Expand Down
4 changes: 2 additions & 2 deletions src/app/api/_hooks/api-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ export const endpoints = {
id: (id: string) => getFullUIEndpoint(`user/${id}`),
update: (id: string) => getFullUIEndpoint(`user/${id}`),
code: (id: string) => getFullUIEndpoint(`user/${id}/code`),
updateEmail: (id: string) => getFullUIEndpoint(`user/${id}/email`)
updateEmail: (id: string) => getFullUIEndpoint(`user/${id}/email`),
transferAll: (id: string) => getFullUIEndpoint(`user/${id}/transfer-all`)
},
wallet: {
balance: (id: string) => getFullUIEndpoint(`wallet/${id}/balance`),
transactions: (id: string) => getFullUIEndpoint(`wallet/${id}/transactions`),
transferAll: (id: string) => getFullUIEndpoint(`wallet/${id}/transferAll`),
nfts: {
root: (id: string) => getFullUIEndpoint(`wallet/${id}/nfts`),
id: (walletId: string, nftId: string) =>
Expand Down
6 changes: 4 additions & 2 deletions src/app/api/_hooks/use-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export function useGetWalletNft(walletId: string, nftId: string) {

// ----------------------------------------------------------------------

export async function transferAll(walletId: string, data: { walletTo: string }) {
const res = await post(endpoints.dashboard.wallet.transferAll(walletId), data, {})
export async function transferAll(userId: string, data: { walletTo: string }) {
console.log('trasnfer all', userId, data)
const res = await post(endpoints.dashboard.user.transferAll(userId), data, {})
console.log('x', res)
return res
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { NextRequest, NextResponse } from 'next/server'

import { transferAll } from 'src/app/api/_data/blk-service'
import { getUserById } from 'src/app/api/_data/data-service'

import { IAccount } from 'src/types/account'

// ----------------------------------------------------------------------

Expand Down Expand Up @@ -42,7 +45,18 @@ export async function POST(req: NextRequest, { params }: { params: IParams }) {
)
}

const result: boolean = await transferAll(walletTo)
const user: IAccount | undefined = await getUserById(id)
if (!user) {
return new NextResponse(
JSON.stringify({ code: 'USER_NOT_FOUND', error: 'user not found with that id' }),
{
status: 404,
headers: { 'Content-Type': 'application/json' }
}
)
}

const result: boolean = await transferAll(user.id, walletTo)
if (!result) {
return new NextResponse(
JSON.stringify({
Expand Down
8 changes: 6 additions & 2 deletions src/components/hook-form/rhf-text-field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ export default function RHFTextField({ name, helperText, type, ...other }: Props
<TextField
{...field}
fullWidth
type={type}
type={type === 'wallet' ? 'text' : type}
value={type === 'number' && field.value === 0 ? '' : field.value}
onChange={(event) => {
let inputValue = event.target.value
if (type === 'number') {
field.onChange(Number(event.target.value))
field.onChange(Number(inputValue))
} else if (type === 'wallet') {
inputValue = inputValue.replace(/[^a-zA-Z0-9]/g, '')
field.onChange(inputValue.startsWith('0x') ? inputValue : `0x${inputValue}`)
} else {
field.onChange(event.target.value)
}
Expand Down
2 changes: 1 addition & 1 deletion src/layouts/common/account-popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default function AccountPopover() {
const OPTIONS = [
{
label: t('menu.account'),
linkTo: paths.dashboard.user.account
linkTo: paths.dashboard.user.root
}
]

Expand Down
2 changes: 1 addition & 1 deletion src/layouts/dashboard/config-navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function useNavData() {
title: t('menu.user'),
path: paths.dashboard.user.root,
icon: ICONS.user,
children: [{ title: t('menu.account'), path: paths.dashboard.user.account }]
children: [{ title: t('menu.account'), path: paths.dashboard.user.root }]
}
]
}
Expand Down
14 changes: 13 additions & 1 deletion src/locales/langs/br.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"user": "UsuΓ‘rio",
"account": "Conta",
"logout": "Sair",
"email": "Alterar Email"
"email": "Alterar Email",
"transfer-all": "Transfer Tudo"
},
"terms": {
"title": "Termos e Condiçáes",
Expand Down Expand Up @@ -290,6 +291,7 @@
"title": "Saldo Estimado",
"deposit": "Depositar",
"send": "Enviar",
"transfer-all": "Transferir Tudo",
"wapp-msg": "OlΓ‘!"
},
"transactions": {
Expand All @@ -305,6 +307,16 @@
"receive-from": "Recebido dinheiro de",
"sent-to": "Enviado dinheiro para"
},
"transfer-all": {
"info": "Indica um endereΓ§o de carteira para onde serΓ£o enviados todos os fundos que vocΓͺ possui no Chatterpay.",
"msgs": {
"ok": "Os fundos foram transferidos. VocΓͺ os verΓ‘ na carteira indicada em breve.",
"error": "Houve um erro ao tentar transferir os fundos."
},
"actions": {
"transfer": "Transferir Tudo"
}
},
"nfts": {
"view-trx": "Ver detalhes da transação",
"mint": "Ei, dΓ‘ uma olhada no meu NFT:",
Expand Down
14 changes: 13 additions & 1 deletion src/locales/langs/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"user": "User",
"account": "Account",
"logout": "Logout",
"email": "Email Change"
"email": "Email Change",
"transfer-all": "Transfer All"
},
"home": {
"header": {
Expand Down Expand Up @@ -290,6 +291,7 @@
"title": "Estimated Balance",
"deposit": "Deposit",
"send": "Send",
"transfer-all": "Transfer All",
"wapp-msg": "Hi!"
},
"transactions": {
Expand All @@ -305,6 +307,16 @@
"receive-from": "Received money from",
"sent-to": "Sent money to"
},
"transfer-all": {
"info": "Indicates a wallet address where all funds in Chatterpay will be sent.",
"msgs": {
"ok": "The funds were transferred. You will see them in the indicated wallet shortly.",
"error": "There was an error attempting to transfer the funds."
},
"actions": {
"transfer": "Transfer All"
}
},
"nfts": {
"view-trx": "View Transacton Details",
"mint": "Hey, check out my NFT:",
Expand Down
14 changes: 13 additions & 1 deletion src/locales/langs/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"user": "Usuario",
"account": "Cuenta",
"logout": "Cerrar SesiΓ³n",
"email": "Cambiar Correo"
"email": "Cambiar Correo",
"transfer-all": "Transferir Todo"
},
"terms": {
"title": "TΓ©rminos y Condiciones",
Expand Down Expand Up @@ -290,6 +291,7 @@
"title": "Balance Estimado",
"deposit": "Depositar",
"send": "Enviar",
"transfer-all": "Transferir Todo",
"wapp-msg": "Hola!"
},
"transactions": {
Expand All @@ -305,6 +307,16 @@
"receive-from": "Recibido dinero de",
"sent-to": "Enviado dinero a"
},
"transfer-all": {
"info": "Indica una direcciΓ³n de billetera en donde se enviarΓ‘n todos los fondos que tengas en Chatterpay",
"msgs": {
"ok": "Los fondos fueron transferidos. Los verΓ‘s en la billetera indicada en breve.",
"error": "Hubo un error al intentar transferir los fondos."
},
"actions": {
"transfer": "Transferir Todo"
}
},
"nfts": {
"view-trx": "Ver detalles de la transacciΓ³n",
"mint": "Hey, mira mi NFT:",
Expand Down
14 changes: 4 additions & 10 deletions src/routes/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,12 @@ export const paths = {
root: `${ROOTS.DASHBOARD}/nfts`,
content: (id: string) => `${ROOTS.DASHBOARD}/nfts`
},
transfer: {
all: `${ROOTS.DASHBOARD}/transfer/all`
},
user: {
root: `${ROOTS.DASHBOARD}/user/account`,
account: `${ROOTS.DASHBOARD}/user/account`,
email: `${ROOTS.DASHBOARD}/user/account/email`,
wallet: {
root: (walletId: string) => `${ROOTS.DASHBOARD}/user/wallet/${walletId}`,
nfts: {
root: (walletId: string) => `${ROOTS.DASHBOARD}/user/wallet/${walletId}/nfts`,
item: (walletId: string, nftId: string) =>
`${ROOTS.DASHBOARD}/user/wallet/${walletId}/nfts/${nftId}`
}
}
email: `${ROOTS.DASHBOARD}/user/account/email`
}
}
}
4 changes: 2 additions & 2 deletions src/sections/account/change-email.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,14 @@ export default function ChangeEmail() {
}, [startCountdown, contextUser, generate2faCodeEmail, t, setValue, enqueueSnackbar])

const handleCancel = () => {
router.push(paths.dashboard.user.account)
router.push(paths.dashboard.user.root)
}

const onSubmit = async (data: any) => {
try {
// @ts-ignore
await updateEmail?.(contextUser!.phoneNumber, data.code || '', confirmEmail, contextUser!.id)
router.push(paths.dashboard.user.account)
router.push(paths.dashboard.user.root)
setErrorMsg('')
enqueueSnackbar(t('common.msg.update-success'))
} catch (ex) {
Expand Down
14 changes: 12 additions & 2 deletions src/sections/banking/banking-balances.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
SelectChangeEvent
} from '@mui/material'

import { paths } from 'src/routes/paths'

import { useBoolean } from 'src/hooks/use-boolean'
import { useResponsive } from 'src/hooks/use-responsive'

Expand All @@ -40,7 +42,6 @@ export default function BankingBalances({
tableData,
...other
}: Props) {

const walletLinkL1 = `${EXPLORER_L1}/address/${tableData?.wallet || ''}`
const walletLinkL2 = `${EXPLORER_L2}/address/${tableData?.wallet || ''}`

Expand Down Expand Up @@ -129,7 +130,6 @@ export default function BankingBalances({
>
{t('balances.deposit')}
</Button>

<Button
fullWidth={!mdUp}
sx={{ maxWidth: mdUp ? 'auto' : '200px', mx: mdUp ? 0 : 4 }}
Expand All @@ -140,6 +140,16 @@ export default function BankingBalances({
>
{t('balances.send')}
</Button>
<Button
fullWidth={!mdUp}
sx={{ maxWidth: mdUp ? 'auto' : '200px', mx: mdUp ? 0 : 4 }}
variant='outlined'
color='warning'
startIcon={<Iconify icon='mdi:arrow-collapse-all' />}
href={paths.dashboard.transfer.all}
>
{t('balances.transfer-all')}
</Button>
</Stack>
)

Expand Down
Loading