-
Notifications
You must be signed in to change notification settings - Fork 447
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into Deon-Branch
- Loading branch information
Showing
39 changed files
with
575 additions
and
190 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,5 @@ | ||
--- | ||
"fuels-wallet": patch | ||
--- | ||
|
||
Allow editing network name when adding. |
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,5 @@ | ||
--- | ||
"fuels-wallet": minor | ||
--- | ||
|
||
Improve handling of custom assets. |
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
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
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` | ||
); | ||
}; |
Oops, something went wrong.