-
Notifications
You must be signed in to change notification settings - Fork 448
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: show more info about contract calls (#1749)
- Closes #1625 --- | 📷 Bako | SwayLend | Bridge | | --- | --- | --- | | <img width="366" alt="Screenshot 2025-01-01 at 21 48 09" src="https://github.com/user-attachments/assets/279fba87-e66a-4228-84ee-a740f1f3bd6d" /> | <img width="375" alt="Screenshot 2025-01-01 at 21 48 43" src="https://github.com/user-attachments/assets/a33b1773-543d-4c87-91b8-b55c70fa05eb" /> | <img width="338" alt="Screenshot 2025-01-01 at 21 52 38" src="https://github.com/user-attachments/assets/1ccc5f2d-2431-4c41-8bcd-58a682a8feda" /> |
- Loading branch information
1 parent
d41f8ec
commit 9cb81db
Showing
22 changed files
with
423 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@fuel-wallet/types": minor | ||
"fuels-wallet": minor | ||
--- | ||
|
||
Add contract logos and names to the transaction screen for better UX. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
packages/app/src/systems/Contract/hooks/useContractMetadata.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import type { Contract } from '@fuel-wallet/types'; | ||
import { Services, store } from '~/store'; | ||
import type { ContractsMachineState } from '../machines/contractsMachine'; | ||
|
||
const selectors = { | ||
contract(id: string) { | ||
return (state: ContractsMachineState): Contract | undefined => { | ||
return state.context.contracts?.find( | ||
(contract) => contract.contractId === id | ||
); | ||
}; | ||
}, | ||
}; | ||
|
||
export const useContractMetadata = (id: string): Contract | undefined => { | ||
const contract = store.useSelector( | ||
Services.contracts, | ||
selectors.contract(id) | ||
); | ||
|
||
return contract; | ||
}; |
81 changes: 81 additions & 0 deletions
81
packages/app/src/systems/Contract/machines/contractsMachine.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import type { Contract, EcosystemProject } from '@fuel-wallet/types'; | ||
import type { InterpreterFrom, StateFrom } from 'xstate'; | ||
import { assign, createMachine } from 'xstate'; | ||
import { FetchMachine } from '~/systems/Core'; | ||
|
||
import { EcosystemService } from '~/systems/Ecosystem/services/ecosystem'; | ||
import { ContractService } from '../services/contracts'; | ||
|
||
export type MachineContext = { | ||
contracts?: Contract[]; | ||
}; | ||
|
||
type MachineServices = { | ||
fetchProjects: { | ||
data: EcosystemProject[]; | ||
}; | ||
}; | ||
|
||
export const contractsMachine = createMachine( | ||
{ | ||
predictableActionArguments: true, | ||
|
||
tsTypes: {} as import('./contractsMachine.typegen').Typegen0, | ||
schema: { | ||
context: {} as MachineContext, | ||
services: {} as MachineServices, | ||
}, | ||
id: '(machine)', | ||
initial: 'fetching', | ||
states: { | ||
fetching: { | ||
invoke: { | ||
src: 'fetchProjects', | ||
onDone: [ | ||
{ | ||
target: 'failure', | ||
cond: FetchMachine.hasError, | ||
}, | ||
{ | ||
target: 'success', | ||
actions: ['assignContracts'], | ||
}, | ||
], | ||
}, | ||
}, | ||
failure: { | ||
after: { | ||
10000: 'fetching', | ||
}, | ||
}, | ||
success: { | ||
type: 'final', | ||
}, | ||
}, | ||
}, | ||
{ | ||
actions: { | ||
assignContracts: assign({ | ||
contracts: (_, ev) => { | ||
return ContractService.formatContractsFromEcosystem(ev.data); | ||
}, | ||
}), | ||
}, | ||
services: { | ||
fetchProjects: FetchMachine.create< | ||
null, | ||
MachineServices['fetchProjects']['data'] | ||
>({ | ||
showError: false, | ||
maxAttempts: 1, | ||
async fetch() { | ||
return EcosystemService.fetchProjects(); | ||
}, | ||
}), | ||
}, | ||
} | ||
); | ||
|
||
export type ContractsMachine = typeof contractsMachine; | ||
export type ContractsMachineState = StateFrom<ContractsMachine>; | ||
export type ContractsMachineService = InterpreterFrom<ContractsMachine>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import type { Contract, EcosystemProject } from '@fuel-wallet/types'; | ||
import { CHAIN_IDS } from 'fuels'; | ||
|
||
// biome-ignore lint/complexity/noStaticOnlyClass: <explanation> | ||
export class ContractService { | ||
static formatContractsFromEcosystem( | ||
projects: EcosystemProject[] | ||
): Contract[] { | ||
return projects.flatMap((project) => { | ||
if (!project.contracts?.mainnet) { | ||
return []; | ||
} | ||
|
||
return project.contracts.mainnet.map((contract) => { | ||
return { | ||
chainId: CHAIN_IDS.fuel.mainnet, | ||
contractId: contract.id, | ||
name: contract.name, | ||
image: project.image, | ||
}; | ||
}); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type { EcosystemProject } from '@fuel-wallet/types'; | ||
import { ECOSYSTEM_PROJECTS_URL } from '~/config'; | ||
|
||
// biome-ignore lint/complexity/noStaticOnlyClass: <explanation> | ||
export class EcosystemService { | ||
static async fetchProjects() { | ||
const res = await fetch(ECOSYSTEM_PROJECTS_URL); | ||
|
||
if (res.ok) { | ||
const data: EcosystemProject[] = await res.json(); | ||
return data; | ||
} | ||
|
||
return []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { IGNITION_NETWORK } from '~/networks'; | ||
import { urlJoin } from '~/systems/Core'; | ||
|
||
export const getProjectImage = (image: string) => { | ||
return urlJoin( | ||
IGNITION_NETWORK.explorerUrl, | ||
`/api/ecosystem/asset/${image}/image` | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.